Why does Matlab run faster after a script is “warmed up”?

前端 未结 4 736
-上瘾入骨i
-上瘾入骨i 2020-12-05 19:01

I have noticed that the first time I run a script, it takes considerably more time than the second and third time1. The \"warm-up\" is mentioned in this question

4条回答
  •  眼角桃花
    2020-12-05 19:14

    Besides Matlab-specific reasons like JIT-compilation, modern CPUs have large caches, branch predictors, and so on. Warming these up is an issue for benchmarking even in assembly language.

    Also, more importantly, modern CPUs usually idle at low clock speed, and only jump to full speed after several milliseconds of sustained load.

    Intel's Turbo feature gets even more funky: when power and thermal limits allow, the CPU can run faster than its sustainable max frequency. So the first ~20 seconds to 1 minute of your benchmark may run faster than the rest of it, if you aren't careful to control for these factors.

提交回复
热议问题