
OK, if somebody wants to speculate (and if it even makes sense for such a microbenchmark) here are some more data. Except different OS and C++ compiler also processor is different. On my side it was AMD Athlon 64 X2 4800+ (2.4GHz, 2x1MiB L2 cache non-shared; C&Q was not switched off during the test). The system has 2GiB RAM. The C++ version had working set about 1.7 MiB, ghc version had it about 2 times bigger. Peter. Dusan Kolar wrote:
Hello all,
just to compare the stuff, I get quite other results being on other OS. Thus, the result of C++ compiler may not be that interesting as I do not have the one presented below.
My machine: Linux 2.6.23-ARCH #1 SMP PREEMPT Mon Oct 22 12:50:26 CEST 2007 x86_64 Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz GenuineIntel GNU/Linux
Compilers: g++ --version g++ (GCC) 4.2.2 Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ghc --version The Glorious Glasgow Haskell Compilation System, version 6.6.1
Measurement: compiled with ghc -O2 time ./mainInteger real 0m4.866s user 0m4.843s sys 0m0.020s
compiled with ghc -O2 time ./mainInt64 real 0m2.213s user 0m2.210s sys 0m0.003s
compiled with ghc -O2 time ./mainInt real 0m1.149s user 0m1.143s sys 0m0.003s
compiled with g++ -O3 time ./mainC real 0m0.271s user 0m0.270s sys 0m0.000s
I don't know what is the reason, but the difference between Int, Int64 and Integer is not that dramatic as in example below, nevertheless, the difference between GHC and GNU C++ is very bad.... :-\
Dusan
Peter Hercek wrote:
Derek Elkins wrote:
Try with rem instead of mod.
(What the heck is with bottom?)
The bottom was there by error and I was lazy to redo the tests so I rather posted exactly what I was doing. I do not know the compiler that good to be absolutely sure it cannot have impact on result ... so I rather did not doctor what I did :-)
Ok, rem did help quite a bit. Any comments why it is so?
Here are summary of results for those interested. I run all the tests once again. Haskell was about 13% slower than C++.
MS cl.exe options: /Ox /G7 /MD ghc options: -O2
C++ version: 1.000; 0.984; 0.984 Haskell version specialized to Int: 1.125; 1.125; 1.109 Haskell version specialized to Integer: 8.781; 8.813; 8.813 Haskell version specialized to Int64: 9.781; 9.766; 9.831
The code:
% cat b.hs module Main (divisors, perfect, main) where import Data.Int
divisors :: Int -> [Int] divisors i = [j | j<-[1..i-1], i `rem` j == 0]
perfect :: [Int] perfect = [i | i<-[1..10000], i == sum (divisors i)]
main = print perfect
% cat b.cpp #include <iostream> using namespace std;
int main() { for (int i = 1; i <= 10000; i++) { int sum = 0; for (int j = 1; j < i; j++) if (i % j == 0) sum += j; if (sum == i) cout << i << " "; } return 0; }
%
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe