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

Author Topic: High CPU use  (Read 1654 times)

0 Members and 1 Guest are viewing this topic.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
High CPU use
« on: April 26, 2012, 10:21:21 am »
We've just started using SFML on yet another new type of hardware, which is a 1.6Ghz Intel Atom (with 1GB RAM), running XP Embedded. My game, which on my Core i3 laptop uses ~3% CPU when idle (and still rendering ~30fps) takes the CPU on the Atom to 97%.

So...what to do? I use a Sleep with 3ms every pass of my game loop, so it's giving a lot of time back to the CPU...I don't think changing this will make any difference. We even reduce the frame rate to 5fps at many points when waiting for user input, to reduce the load from CPU as much as possible.

Does anyone have any ideas? I'd really appreciate some input :-)

Thanks
Ed
SFML 2.1

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
Re: High CPU use
« Reply #1 on: April 26, 2012, 10:29:18 am »
I'm not sure how you reduce the display to 5fps, can you ellaborate?

Also do you use sf::RenderWindow::setFramerateLimit(int)?
This should call sleep() on its own an guarantee a framerate around the given number. Thus if you don't do anything it will sleep longer and if you do a lot of calculation it will sleep less.

Additionally does the PC with 97% CPU usage have a proper graphics card?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: High CPU use
« Reply #2 on: April 26, 2012, 10:31:54 am »
You should first profile your app, it's hard to optimize when you don't know what to optimize :)

Then if it's something not too specific to your app, you should be able to reproduce it in a minimal example that we can test.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: High CPU use
« Reply #3 on: April 26, 2012, 10:34:38 am »
Hi

Yes we use SetFramerateLimit, this is set to 60fps by default, and then we have our own internal frame timer, and we just update the screen based on this timer. I guess I could call SetFramerateLimit too with the fps we're currently doing?

Thanks
SFML 2.1