On Monday 12 of January 2004 16:59, David Garamond wrote: > Emmanuel Touzery wrote: > > i have the feeling (unconfirmed) that perl is optimising it away since > > the result is unused or the operation repeated or something. i created a > > file with 1000000 lines repeating the addition and perl is very slow too > > then (and ruby too). > > do you mean you did: > > #!/usr/bin/{perl,ruby} > 1234567+123456; > 1234567+123456; > 1234567+123456; > 1234567+123456; > 1234567+123456; > ... > > ? > > then have you factored out compilation overhead? I would wild-guess that > Perl is slightly slower than Ruby, due to its complex syntaxes? i did try with a file as you said, but due to a slow computer i had to kill it before the end. when i first ran it, i saw perl was slow, which seemed to confirm this 'perl is caching the result' intuition, i didn't think about the syntax parsin overhead :O) now i tried on a faster computer: [emmanuel@papillon emmanuel]$ time perl test.rbpl 10.63user 1.01system 0:35.49elapsed 32%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (6628major+98402minor)pagefaults 0swaps [emmanuel@papillon emmanuel]$ time ruby test.rbpl test.rbpl:8127:in `+': Bignum can't be coerced into Fixnum (TypeError) from test.rbpl:8127 Command exited with non-zero status 1 26.86user 0.71system 0:28.19elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (254major+51518minor)pagefaults 0swaps i'm not really sure why ruby is choking on line 8127, all lines are identical and read '1073741823+1073741824;' but anyway it shows that in any case ruby is still much slower than perl, so nevermind what i said. as far as i'm concerned, it's not sure at all that perl is saving the calculation. my initial impression was simply caused by the huge difference between ruby and perl. emmanuel PS: if someone is interested in this ruby error, the file is too big to send, but is so that: [emmanuel@papillon emmanuel]$ uniq test.rbpl 1073741823+1073741824; [emmanuel@papillon emmanuel]$ wc -l test.rbpl 1000001 test.rbpl PPS: great trick with NArray.. :O)