RosettaCode factorial needs to use longs
Jay Norwood
jayn at prismnet.com
Sat Mar 8 10:11:56 PST 2014
After changing to longs, I made some test loops, and on release
build dmd, pc, these are the relative times I measured for the
different versions of factorial in that example. So the
iterative wins, and the functional style results in 4x penalty in
this case.
duration factorial (hnsecs)=98
duration recFactorial (hnsecs)=151
duration fact (hnsecs)=418
duration tfactorial (hnsecs)=131
each test was like this:
sw.reset();
sw.start();
for (long i=15; i<50; i++){
rv+=i.tfactorial;
rv-=i.tfactorial;
}
sw.stop();
writeln("duration tfactorial (hnsecs)=", sw.peek().hnsecs);
More information about the Digitalmars-d-learn
mailing list