From: William James Date: 2007-01-18T15:10:13+09:00 Subject: Re: Intensive computing: Ruby? Ruby/C? Pure C++? William James wrote: > Shot (Piotr Szotkowski) wrote: > > Thanks a lot for taking the time to reply, Benjohn! > > > > benjohn@fysh.org: > > > > > I'd go with prototype in Ruby, probably. > > > > And then...? I hoped a bit for the dream solution of "actually, dear > > professors, it works - if slow - for the scope of this thesis, and > > further speed improvements can be achieved by replacing more parts > > with C/C++ code". ;) > > > > > You could jump in to c++, and I think you may find useful Boost > > > libraries for the work you're going (there is a graph librarby in > > > there, I'm sure) > > > > Yeah, I heard good things about Boost, and also that wrapping one's mind > > around C++ templating is a requirement these days. Of which, the latter > > scares me (and I seem to know my limits quite well)... > > > > > but I honestly think you'll suffer if you're not a c++ Guru > > > > My thoughts exactly. The catch is my supervisor codes in C++ all his > > life, while not having any idea about script languages, so he doesn't > > really seem to easily buy mine 'I'll code both faster and be way more > > happy with Ruby/OCaml, and the finished libraries will be more-or-less > > universal anyway.' > > > > > After prototyping, a fourth way that I would strongly suggest in > > > this case, is to considder a functional language if you need speed. > > > > The catch with going OCaml (where did today go? all these > > easily-googlable tutorials and opinions were so nice to read...) > > is that I'll have to learn yet another language (and, more importantly, > > design paradigm). > > LuaJIT probably won't be as fast as OCaml, but I think Lua > is easier for a Rubyist to learn. Comparing Ruby to Lua and LuaJIT for intensively computing primes: Ruby 245.763 seconds Lua 10.685 seconds LuaJIT 1.311 seconds # the Ruby program def prime(n) if n > 2 and n % 2 == 0 return false end 3.step( Math.sqrt(n).floor, 2){|i| if n % i == 0 return false end } true end puts prime(2) puts prime(4) puts prime(7) puts prime(25) puts '----- the rest are primes' time = Time.now puts prime(1073676287) puts prime(68718952447) puts prime(87178291199) puts prime(274877906899) puts prime(549755813881) puts prime(1099511627689) puts prime(2199023255531) puts prime(4398046511093) puts prime(8796093022151) puts prime(17592186044399) puts prime(953467954114363) puts Time.now - time -- the Lua program function prime(n) if n > 2 and n % 2 == 0 then return false end for i = 3, math.floor(math.sqrt(n)), 2 do if n % i == 0 then return false end end return true end print(prime(2)) print(prime(4)) print(prime(7)) print(prime(25)) print('----- the rest are primes') time = os.clock() print(prime(1073676287)) print(prime(68718952447)) print(prime(87178291199)) print(prime(274877906899)) print(prime(549755813881)) print(prime(1099511627689)) print(prime(2199023255531)) print(prime(4398046511093)) print(prime(8796093022151)) print(prime(17592186044399)) print(prime(953467954114363)) print(os.clock() - time)