Hi,

In message "Re: String#== vs. Symbol#== speed  (was Re: Symbol < String in Ruby > 1.8)"
    on Fri, 27 Oct 2006 14:27:21 +0900, Sam Roberts <sroberts / uniserve.com> writes:

|Of course, code is below. Its in the context of profiling I did of an
|iCalendar parser. There is a lot of comparisons of short strings,
|case-insensitively.

By this benchmark, their difference could be found by comparing the
first character, so that

symbol

  sym1 == sym2  # comparison done

string

  str1 == str2
  str1.size == str2.size
  str1[0] == str2[0]

did not make huge difference.  Try the following program to see the
comparison performance difference between Strings and Symbols.

require 'benchmark'
require 'pp'

str0 = "a" * 2000
str1 = str0.dup
str1[-1] = "b"

$N = 1000000
Benchmark.bm(20) do |x|

  x.report("noop")  do
    $N.times do
    end
  end

  x.report("String#==")  do
    $N.times do
      str0 == str1
    end
  end

  x.report("Symbol#==")  do
    $N.times do
      sym0 == sym1
    end
  end
end