Mailinglist Archive: yast-devel (48 mails)

< Previous Next >
[yast-devel] Ruby Idioms Benchmarks

Hi all,

I found quite interesting page with speed comparison of Ruby idioms, see [1].

For YaST the speed is not critical as the most time consuming actions
are usually outside YaST itself (starting services, running scripts or external
tools, installing packages...).

But it's good to know that if you need to speed up a critical part of your
application some tricks might help.

Unfortunately some tricks results in less readable code so you need
to compare the speed improvement vs. code readability.

As mentioned above in YaST the speed is usually not an issue so the
better readable variant should be usually preferred. But in some specific cases
the faster variant might make sense.

So did you know that...

- Hash#keys.each is about 20% slower than Hash#each_key ?
- Array#first is about 15% slower than Array#[0] ?
- "foo" + "bar" is about 1.8x slower than "foo" "bar" ?

Check the document for more examples.

Note: Obviously it very depends on the version of the Ruby interpreter and the
used in the tests, e.g. the "foo" + "bar" result might be completely different
the "very_long_string..." + "another_very_long_string..." result.

Fortunately all benchmarks contain a link to the used code, you can modify it
and test a scenario which is more close to your use case.



Ladislav Slez√°k
Appliance department / YaST Developer
Lihovarsk√° 1060/12
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages