Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SMFL2 & CPU usage  (Read 2052 times)

0 Members and 1 Guest are viewing this topic.

zyroph

  • Guest
SMFL2 & CPU usage
« on: August 30, 2013, 12:24:17 pm »
Hi all,

I'm totally new to SFML and as a first test I took that very simple program drawing a green circle as provided at the end of the install tutorial.

I'm running:
  • On a Intel Quad Core,
  • Under Windows XP Pro X64 edition,
  • Using Codeblocks and Mingw,
  • In static mode,
and I actually had to recompile my own version as none of the provided works for me.

However, I was very surprised to notice two performance issues:
  • After launching the execution, whether in debug or release mode, I have sometimes to wait something like 20s before the window appears.
  • Once the program launched, it uses nearly a hole CPU core all the time, swinging between 21% and 25% of the total CPU.
It's really weird as I never came across such issues using other libraries, knowing the program is as simple as possible.

So any ideas? And thanx in advance...

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: SMFL2 & CPU usage
« Reply #1 on: August 30, 2013, 12:31:45 pm »
Take a look at the FPS your program is running at. You'll  notice that it's ridiculously high. That is because your main loop is being executed as fast as possible and since it doesn't do much your program is running really fast. This is filling up a whole core (25%of your CPU)
So you should limit you framerate to something that is normal (like 60 FPS) or use vertical sync. This gives your program some time to sleep and doesn't waist CPU time.
Cheers

zyroph

  • Guest
Re: SMFL2 & CPU usage
« Reply #2 on: August 30, 2013, 01:04:56 pm »
Wow, worked like a charm.

Hmm,... but isn't something that should be set by default in the lib? Or at least included in the tutorial program?

Anyway, cheers for one of the fastest working answer I ever got in a forum!

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: SMFL2 & CPU usage
« Reply #3 on: August 30, 2013, 01:15:44 pm »
Wow, worked like a charm.

Hmm,... but isn't something that should be set by default in the lib? Or at least included in the tutorial program?

Anyway, cheers for one of the fastest working answer I ever got in a forum!

This isn't a video game librairy but a multimedia librairy. It's the developper responsability to limit the framerate if he needs it.
Plus there's a method in sf::RenderWindow that allow you to limit the framerate or enable v-sync. But if you want more control on the framerate and how many times update and draw are executed, the best is to handle it yourself.

 

anything