[Bf-committers] sqrt code snippet

Kent Mein bf-committers@blender.org
Thu, 3 Jun 2004 10:11:00 -0500


In reply to Janek Kozicki (janek_listy@wp.pl):

> I wrote this piece of code to benchmark speed of sqrt(). I did it in
> three minutes, so don't flame me for... umm? bad code ;)
> 
> Uncomment respective lines then compile.
> 

Here are my results, I did 3 runs of each on each platform.(Linux,OSX,Solaris)
For solaris and OSX I used g++ and had to use __builtin_sqrtf,__builtin_sqrtl
I thought for solaris using CC sqrt is overloaded so its just sqrt for all
of them but when I tried to look on the web I couldn't find anything.  We
should probably figure out the correct way to call it for other compilers at
least for Solaris even though its not working with CC currently. ;)

Kent

	Linux:
		sqrtf:
[10:06] ~(mein@jessica) % time a.out
0.670u 0.000s 0:00.78 85.8%     0+0k 0+0io 199pf+0w
[10:06] ~(mein@jessica) % time a.out
0.670u 0.000s 0:00.78 85.8%     0+0k 0+0io 199pf+0w
[10:06] ~(mein@jessica) % time a.out
0.670u 0.000s 0:00.78 85.8%     0+0k 0+0io 199pf+0w
		sqrt:
[10:06] ~(mein@jessica) % time a.out
1.020u 0.000s 0:01.18 86.4%     0+0k 0+0io 199pf+0w
[10:07] ~(mein@jessica) % time a.out
1.010u 0.000s 0:01.17 86.3%     0+0k 0+0io 199pf+0w
[10:07] ~(mein@jessica) % time a.out
1.010u 0.000s 0:01.17 86.3%     0+0k 0+0io 199pf+0w
		sqrtl:
[10:07] ~(mein@jessica) % time a.out
1.860u 0.000s 0:02.17 85.7%     0+0k 0+0io 199pf+0w
[10:07] ~(mein@jessica) % time a.out
1.860u 0.000s 0:02.17 85.7%     0+0k 0+0io 199pf+0w
[10:07] ~(mein@jessica) % time a.out
1.870u 0.000s 0:02.17 86.1%     0+0k 0+0io 199pf+0w

	OSX:
		sqrtf:
[xserve:~] mein% time ./a.out
3.890u 0.050s 0:04.52 87.1%     0+0k 0+0io 0pf+0w
[xserve:~] mein% time ./a.out
3.890u 0.010s 0:04.05 96.2%     0+0k 0+0io 0pf+0w
[xserve:~] mein% time ./a.out
3.980u 0.020s 0:04.13 96.8%     0+0k 0+0io 0pf+0w
		sqrt:
[xserve:~] mein% time ./a.out
4.140u 0.020s 0:04.35 95.6%     0+0k 0+0io 0pf+0w
[xserve:~] mein% time ./a.out
4.490u 0.010s 0:04.48 100.4%    0+0k 0+1io 0pf+0w
[xserve:~] mein% time ./a.out
4.250u 0.010s 0:04.40 96.8%     0+0k 0+0io 0pf+0w
		sqrtl:
[xserve:~] mein% time ./a.out
4.290u 0.010s 0:04.27 100.7%    0+0k 0+0io 0pf+0w
[xserve:~] mein% time ./a.out
4.170u 0.010s 0:04.31 96.9%     0+0k 0+0io 0pf+0w
[xserve:~] mein% time ./a.out
4.200u 0.010s 0:04.32 97.4%     0+0k 0+0io 0pf+0w

	Solaris:
		sqrtf:
[9:54] ~/tmp(mein@cc) % time a.out
4.38u 0.02s 0:04.39 100.2%
[9:54] ~/tmp(mein@cc) % time a.out
4.37u 0.02s 0:04.38 100.2%
[9:54] ~/tmp(mein@cc) % time a.out
4.36u 0.02s 0:04.38 100.0%
		sqrt:
[9:55] ~/tmp(mein@cc) % time a.out
6.33u 0.01s 0:06.35 99.8%
[9:55] ~/tmp(mein@cc) % time a.out
6.32u 0.00s 0:06.36 99.3%
[9:55] ~/tmp(mein@cc) % time a.out
6.33u 0.02s 0:06.35 100.0%
		sqrtl:
[9:56] ~/tmp(mein@cc) % time a.out
54.12u 0.01s 0:54.17 99.9%
[9:57] ~/tmp(mein@cc) % time a.out
54.08u 0.01s 0:54.13 99.9%
[9:58] ~/tmp(mein@cc) % time a.out
54.14u 0.02s 0:54.45 99.4%