雨谷の日和

過去20年で2,700を超えるアニメの第1話だけは見続けた僕のお勧めアニメがハズレなはずがない

Cでの行列式計算(malloc/freeでの実装)の結果

2004.04.02付けの「Cでの行列式計算(malloc/freeでの実装)」のソースコードを用いてその実行に掛かる時間を測ってみる。
なお、実行環境は以前と同じでPentium4:2.4GHz + WindowsXP + cygwin + gcc3.3.1 である。
最適化の深度の違いも考慮したいので、コンパイルは以下のようにして行った。

#! /bin/sh

gcc -o test.exe test.c gcc -O0 -o test0.exe test.c gcc -O1 -o test1.exe test.c gcc -O2 -o test2.exe test.c gcc -O3 -o test3.exe test.c

出来た実行ファイルは、以下のようにして順に実行する。

#! /bin/sh

date '+%H:%M:%S' ./test.exe date '+%H:%M:%S' ./test0.exe date '+%H:%M:%S' ./test1.exe date '+%H:%M:%S' ./test2.exe date '+%H:%M:%S' ./test3.exe date '+%H:%M:%S'

この結果が、以下である。
今回は標準出力に結果が出力されるので、時間の表示の他に、それぞれの実行結果が間に出力されている。

19:59:41
result: 489261678
20:00:27
result: 489261678
20:01:13
result: 489261678
20:01:56
result: 489261678
20:02:39
result: 489261678
20:03:22

最適化無しだと約46秒、最適化有りだと約43秒という結果となった。
次はJavaのものの実行profileを見てみよう。