19

初めてスクリプトを実行するときは、2 回目、3 回目よりもかなり時間がかかることに気付きました1。「ウォームアップ」は、説明なしでこの質問に記載されています。

「ウォームアップ」後にコードの実行が速くなるのはなぜですか?

clear all呼び出し間ではありません2が、関数呼び出しごとに入力パラメーターが変化します。これがなぜなのか誰か知っていますか?


1. ライセンスをローカルに持っているので、ライセンスの確認に関する問題はありません。

2. 実際には、 I の場合、動作は変わりませんclear all

4

4 に答える 4

2

Matlab が解釈されます。コードをウォームアップしないと、実際のアルゴリズムではなく解釈のために多くの時間を失うことになります。これにより、タイミングの結果が大幅に歪む可能性があります。

コードを少なくとも 1 回実行すると、Matlab が適切なコード セグメントを実際にコンパイルできるようになります。

于 2013-06-01T15:09:51.047 に答える
1

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.

于 2016-06-29T14:37:24.457 に答える