From: Stefan Matthias Aust Date: 2001-05-07T02:40:04+09:00 Subject: [ruby-talk:14746] Re: Why's Ruby so slow in this case? Mathieu, thanks for your kind reply. In the meantime I noticed myself that the profiler was responsible. Too bad. This greatly reduced the usefulness of the current profiler IMHO. A better approach, which is followed by all Smalltalk system I know is not to exactly count method calls but to sample the call stack in certain intervalls. For Squeak, this method has no visible slowdown while still generating very useful data. Just a thought. Mathieu Bouchard wrote: >In Ruby, cases _have_ to be tested sequentially, unlike C, which allows >integers only, and can optimize situations like this using a static array >of gotos. I don't think, the case/when stuff was responsible for the slowdown. It's just that a few milliseconds on each of the some 100_000 calls eventually sum up. >> def xytoh(x, y) >> [...] >Those seem to be almost-unnecessary abstractions. I would be quite tempted >to eliminate them. Well, I disagree. Readably should always come first. Even for a scripting language like Ruby, I expect the execution environment to optimize stuff. That shouldn't be the responsibility of the user. Furhermore, these little methods define a coordinate mapping with is quite central for that module, so I'd better not manually inline these calls. >>[onmap in Smalltalk] >I translated that piece of code back into Ruby and compared with GNU >Smalltalk. It's only about 4 times slower. Here is the code I used: So, the question remains, is Squeak at least two times faster than GNU Smalltalk (which version, BTW)? On my machine, your Ruby code needs 0.555s to run, that is 4 times slower than Squeak. PS: I like that benchmark module. Why isn't it part of the standard distribution? bye -- Stefan Matthias Aust \/ Truth Until Paradox