Re: [Template-haskell] On reifing functions and partial evaluation
On Tue, 2004-02-17 at 09:05, Alastair Reid wrote:
First the sensational headline: ghc beats gcc by 57% on Ackerman benchmark, improved to 290% using Template Haskell.
Any thoughts on how it would compare with a C++ template-based version of ack? Off the top of my head, I'd say performance ought to drop back to nearer the 57% better mark but it'd be (mildly) interesting to confirm this.
Ok, so to be fair to C/C++ (!) we should really compare like with like in which case we should compare our template-unrolled version with a C++ template unrolled version. As you thought, the performance drops back, but we still win. :-) 75 sec for g++-3.3.2 -O3 -fomit-frame-pointer 40 sec for genex_ack_4 with ghc -O So the percent improvement that the marketing folk would put in their adds would be 87%. So actually we're winning by a greater margin than before. If you're really keen we can get the time down even further: 88 sec for ack_4 with ghc -O2 -fvia-C -optc-O2 (vs 100sec for ghc -O) 32 sec for genex_ack_4 with ghc -O2 -fvia-C -optc-O2 (vs 40sec for ghc -O) Duncan Here's the C++ code: template<int m> class foo { public: static int ack(int n) { if (n==0) return foo<m-1>::ack(1); else return foo<m-1>::ack(ack(n-1)); } }; template<> class foo<0> { public: static int ack(int n) { return n+1; } }; int main (int argc, char *argv[]) { int n = ((argc == 2) ? atoi(argv[1]) : 1); printf("ack 4 %d = %d\n", n, foo<4>::ack(n)); return 0; }
participants (1)
-
Duncan Coutts