Franz Hartmann wrote: >> Franz, >> I have myself somehow tested this and unfortunately, ruby shall not >> take advantage of the dual CPU. The example I used for this was the >> calculation of the factorial of 100000. This is IMHO a good example to >> discuss the performance question. > > > Yes, and i am schocked... i have a pentium 3 box (900 mhz) which give me > 1800 mips and it needs 14 min 43 secfor the calculation of 100000 > multiplications. > 14 x 60 + 43 sec = 883 sec > 100000 operations / 883 sec = 113 flops??? > c64 basic calculated 10000 sqrts within less than 20 minutes, that > amount to 10000 / 1200 = 8 flops. at 0.9 mhz, that is 1/1000. > (8 / 113) / (0.9 / 900) = 70.8 > Does this mean that ruby is 70 (seventy) times slower than c64 basic, > not counting the advantages of 32 vs 8 bit???? > Or did i just make some very stupid error? Here's the program: > > > def fac( n ) > f = 1 > (1..n).each { |x| f *= x } > return f > end > > print "%d\n" % fac( ARGV[0].to_i ) > Ruby may be slow, but not that slow. In your computation, you did not do floating point computations, but arbitrary size integer computations. Multiplication of an ~100000 digit integer by another integer is quite costly. Therefore it took so long. Here is a test for floating point operations: def harm(n) (1..n).inject(1.0) {|a, b| a + 1.0 / b} end which computes the n'th harmonic number (1 + 1/2 + 1/3 + ... + 1/n). harm(100000) takes about 1 second on my system. xyzzy, Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm / isis-papyrus.com Visit our Website: www.isis-papyrus.com