From: "Simon Kröger" Date: 2006-05-23T05:12:14+09:00 Subject: Re: Zed and Luis drop the bomb on Ruby's poor performance Hi Sam! user system total real > noop 0.700000 0.000000 0.700000 ( 0.698633) > String#== 2.410000 0.010000 2.420000 ( 2.445288) > String#casecmp 2.650000 0.000000 2.650000 ( 2.652620) > Symbol#== 2.280000 0.000000 2.280000 ( 2.274505) > String#to_sym 2.460000 0.000000 2.460000 ( 2.449362) > String#up 4.730000 0.000000 4.730000 ( 4.721140) > String#up#to_sym 6.030000 0.000000 6.030000 ( 5.986897) [...] x.report("Fixnum#==") do $N.times do 0 == 1 end end [...] x.report("String#up!") do $N.times do str1.upcase! end end [...] user system total real noop 0.157000 0.000000 0.157000 ( 0.156000) Fixnum#== 0.390000 0.000000 0.390000 ( 0.391000) String#== 0.438000 0.000000 0.438000 ( 0.437000) String#casecmp 0.578000 0.000000 0.578000 ( 0.594000) Symbol#== 0.390000 0.000000 0.390000 ( 0.390000) String#to_sym 0.563000 0.015000 0.578000 ( 0.579000) String#up 1.437000 0.016000 1.453000 ( 1.484000) String#up! 0.532000 0.000000 0.532000 ( 0.531000) String#up#to_sym 1.890000 0.000000 1.890000 ( 1.922000) Well i think in this trivial cases the problem isn't the string compare or whatever C algorithm is called - the problem is the call itself. (two trivial fixnum compares are already more expensive than a single String compare) String#upcase constructs a new object (using the bang method is way faster) Conclusion: method calls in general and object creation are the bottlenecks in this (very, very) simple cases. cheers Simon