[gambit-list] a simple question for optimization

Bradley Lucier lucier at math.purdue.edu
Fri Apr 10 20:52:28 EDT 2015


> On Apr 10, 2015, at 6:12 PM, Bradley Lucier <lucier at math.purdue.edu> wrote:
> 
> Long answer:
> 
> [Media-Mac-mini-3:~] lucier% time ./pi 1000000
> (time (cpi k))
>    18 ms real time
>    17 ms cpu time (17 user, 0 system)
>    no collections
>    64 bytes allocated
>    no minor faults
>    no major faults
> 3.1415946535887644
> 0.021u 0.009s 0:00.09 22.2%     0+0k 0+0io 753pf+0w
> 
> So that last bit didn't help too much.
> 
> On my machine I get
> 
> [Media-Mac-mini-3:~] lucier% g++ -Wall -W -Ofast pi.cc
> pi.cc:12:14: warning: unused parameter 'argc' [-Wunused-parameter]
> int main(int argc, char* argv[]) {
>             ^
> 1 warning generated.
> [Media-Mac-mini-3:~] lucier% time ./a.out 1000000
> 3.1415926535899388
> 
> 0.018200999999999998
> 0.018u 0.001s 0:00.02 50.0%     0+0k 0+0io 0pf+0w
> 
> Pretty close.

Sorry, I didn’t use the same compiler for Scheme and C++:

[Media-Mac-mini-3:~] lucier% gsi -v
v4.7.4 20150228031125 x86_64-apple-darwin14.1.0 "./configure 'CC=/pkgs/gcc-4.9.1/bin/gcc' '--enable-single-host' '--enable-multiple-versions'"
[Media-Mac-mini-3:~] lucier% /pkgs/gcc-4.9.1/bin/g++ -Wall -W -Ofast pi.cc
g++: warning: couldn't understand kern.osversion '14.3.0
pi.cc:12:14: warning: unused parameter 'argc' [-Wunused-parameter]
 int main(int argc, char* argv[]) {
              ^
[Media-Mac-mini-3:~] lucier% time ./a.out 1000000
3.1415926535897647

0.0090840000000000001
0.010u 0.002s 0:00.36 2.7%      0+0k 0+0io 57pf+0w


So the C++ program is still about twice as fast (if you can believe timings that small).

Brad


More information about the Gambit-list mailing list