Here are notes about the Ruby language.
After reading an article talking about applying the Actor pattern for GUI, I decided to write the example in JRuby (the original article presented a Java version and a Python version).
The JRuby implementation is easier to use (and to understand) than the Java version (see the article).
Are you playing with method_missing? Did you hear it could lead to inefficient code? Here is an example and some benchmarks (see the article for a complete explanation).
As a quick summary, the benchmark runs some test first by calling a normal method (see Normal method), next by always going through the method_missing (see Always missing). Then, it adds a new method, so that next time the method does exist (see Create method). Finally, it adds a new optimized method (Optimized).
Next are the results produced on a Windows-XP system, with Ruby 1.8.5.
user system total real Normal method 0.681000 0.000000 0.681000 ( 0.681000) Always missing 1.161000 0.000000 1.161000 ( 1.161000) Create method 0.822000 0.000000 0.822000 ( 0.821000) Optimized 0.070000 0.000000 0.070000 ( 0.071000)
Creating a method has 30% of gain. The optimized version is even much better (93% of gain) but is specific to the example. Except the optimized version, the other two are less efficient than a normal call (the better one adds 21% overhead).
The same test on a Linux box, with Ruby 1.8.5, produces:
user system total real Normal method 0.950000 0.110000 1.060000 ( 1.092198) Always missing 1.520000 0.140000 1.660000 ( 1.684640) Create method 1.210000 0.090000 1.300000 ( 1.330977) Optimized 0.100000 0.030000 0.130000 ( 0.154522)
The exact gain percentage is different, still we see that creating a method improves performance but is not as good as normal calls. Of course, the optimized version remains the best.