07/07/03 16:15:19
>>594
こんなコードを書いてみる。
#include <stdio.h>
#include <stdlib.h>
int main()
{
volatile int a;
volatile int b;
for (int ic = 0; ic < 100 * 1000 * 1000; ++ic) {
#if 1
volatile int c = abs(a) > abs(b);
#else
volatile int c = a * a > b * b;
#endif
}
return 0;
}
こいつをこんな感じで実行してみる。
$ gcc foo.c -std=c99 -O3 ; time ./a
foo.c: In function `main':
foo.c:11: warning: unused variable `c'
real 0m0.734s
user 0m0.687s
sys 0m0.047s
意外にも、abs()の方が遅かった。