From: "Bartosz Dziewoński" Date: 2012-03-25T02:11:31+09:00 Subject: Re: Ruby speed compared to C in a simple calculations. W dniu 24 marca 2012 17:45 użytkownik Роман Ткаленко napisał: > #works for 3.55 mins > > Code written in C gives me the solution in only 2 seconds. I suppose that > it's called not by ruby slowlyness, but my shitty coding abilities. Cuold > tou please tell me the weaknesse of the code? It took 51 seconds for me on Ruby 1.9.3, on a laptop; the 1.9 series is much faster than 1.8. Ruby, overall, is unfortunately very slow. There are many reasons for this (for example, every operator is your code becomes a method call, and every method call requires looking up the relevant code in a method table - this adds up), and not much can be done. For some reason even the bare "(0 .. P).each do | i |" loop (with everything inside removed) takes 30 seconds to run, and so does a P.times or a while loop (negligible time difference). You just can't do fast computation in Ruby now, at all. (Note that JRuby or Rubinius might be faster for numeric computation - try yourself, if you care.) -- Matma Rex