I found quite interesting page with speed comparison of Ruby idioms, see .
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# ?
- "foo" + "bar" is about 1.8x slower than "foo"
Check the document for more examples.
Note: Obviously it very depends on the version of the Ruby interpreter and the data
used in the tests, e.g. the "foo" + "bar" result might be completely
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.
Appliance department / YaST Developer
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
To unsubscribe, e-mail: yast-devel+unsubscribe(a)opensuse.org
To contact the owner, e-mail: yast-devel+owner(a)opensuse.org