Why is the performance of a running program getting better over time?

后端 未结 2 1174
情深已故
情深已故 2021-02-19 21:33

Consider the following code:

#include 
#include 

using Time = std::chrono::high_resolution_clock;
using us = std::chrono::microsec         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 21:48

    What you are probably seeing is CPU frequency scaling (throttling). The CPU goes into a low-frequency state to save power when it isn't being heavily used.

    Just before running your program, the CPU clock speed is probably fairly low, since there is no big load. When you run your program, the busy loop increases the load, and the CPU clock speed goes up until you hit the maximum clock speed, decreasing your times.

    If you run your program several times in a row, you'll probably see the times stay at a lower value after the first run.

提交回复
热议问题