Posted by herkules
on July 19, 2010 at 4:44 AM PDT
Recently I was in urged to do a web project with the latest and coolest web framework Ruby on Rails. One line of code sprang to me eyes......
Recently I was in urged to do a web project with the latest and coolest web framework Ruby on Rails.
That's just one line of code grabbed from somewhere:
next if entry =~ /^\./
Ruby is said to read like a natural language, but for my eyes this is just a cryptic sequence. Maybe I have the wrong natural language. So to clarify what it means I translated it to some assembly language:
Yes: if the entry begins with '.', skip it.
The latter code might take 2 CPU cycles to execute.
How much will the Ruby code take? There is the line to be interpreted (syntax check, AST creation,... no idea), than a regexp engine is started which starts parsing the expression before it tries to find a match. All this is accompanied by lots of heap activity. My guess: 100.000 cycles. At least.
So it's 50.000 times slower than it needs to be to get the work done. Who needs a cluster of 50.000 machines to serve his application? Well, all others should be well of with a single server, even a poor one, if it only was programmed with care.
I know it's unfair and untrue, so please don't comment on that. But ... to some respect it is true.