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

Author Topic: SFML HelloWorld example takes 20% of my CPU ressources  (Read 2470 times)

0 Members and 1 Guest are viewing this topic.

roughbits01

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML HelloWorld example takes 20% of my CPU ressources
« on: January 10, 2017, 04:12:40 pm »
So I compiled and ran the example code of setting up a window found here http://www.sfml-dev.org/tutorials/2.4/start-linux.php and I did the same with GLFW http://www.glfw.org/documentation.html

               
CPU usage (%)Memory usage (MB)
SFML2024
GLFW114

Can someone help me understand why does SFML seem to take up more CPU resources while polling for events?
« Last Edit: January 10, 2017, 04:15:38 pm by roughbits01 »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: SFML HelloWorld example takes 20% of my CPU ressources
« Reply #1 on: January 10, 2017, 04:47:36 pm »
Are you sure it is the polling for events that is causing high CPU usage? Typically, unless there is something put in there to intentionally slow it down, the CPU of your computer will run any program as fast as it can. Like most game loops, that hello world code uses what is essentially an infinite loop to keep it running.  It will just spin in that loop as fast as it can because it has no reason not to. This usually will result in one of the cores of your CPU being utilized to almost 100%.

Most games will add something to allow the CPU to take a break each loop of the game logic or so. A good place to start may be to to enable Vsync or lock the framerate to some value. See the official tutorials on controlling the framerate

Having said that, I don't know anything about GLFW to know why that linked example uses so little CPU. Maybe vsync is enabled by default?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: SFML HelloWorld example takes 20% of my CPU ressources
« Reply #2 on: January 11, 2017, 02:38:34 pm »
Your GPU drivers most likely default to vertical sync being off. As such you're essentially CPU bound (i.e. max load on one core) since there's nothing to do for the GPU.

Try calling window.setVerticalSyncEnabled(true); after you've created the window.