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

Author Topic: [SOLVED] High CPU usage with almost nothing  (Read 2464 times)

0 Members and 1 Guest are viewing this topic.

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
[SOLVED] High CPU usage with almost nothing
« on: May 23, 2018, 01:32:24 am »
Why a single code like this can consume about 15% of CPU usage in a Intel I7 processor?

Code: [Select]
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(800, 600), "Janela", Style::Close);
window.setFramerateLimit(120);
while (window.isOpen())
{
for (Event event; window.pollEvent(event);) {
if (event.type == Event::Closed)
window.close();
}

}
return EXIT_SUCCESS;
}
« Last Edit: May 23, 2018, 03:57:20 pm by rogeriodec »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: High CPU usage with almost nothing
« Reply #1 on: May 23, 2018, 06:38:13 am »
setFramerateLimit has no effect if you never call window.display().
Laurent Gomila - SFML developer

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: [SOLVED] High CPU usage with almost nothing
« Reply #2 on: May 23, 2018, 03:57:48 pm »
Perfect.
Thank you very much!