On Thu, 29 Dec 2005, Johannes Friestad wrote:


> Symbols are (or can be) quicker for hash lookup, since it is sufficient to
> compare object identity to find whether two symbols are the same, while
> strings must be compared character by character. You are unlikely to notice
> the difference unless your program uses hashes heavily.

i see this claim all the time but never data supporting it, all my test
programs have shown the opposite to be true.  see

   http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/c881186317ef8d33/e20e6e93c99b9924?q=symbol+string+hash+speed+howard&rnum=1#e20e6e93c99b9924

for some sample code.

running that sample code with the latest ruby (1.8.4) shows the gap has
narrowed, but strings are still beating symbols on my box:

   ---
    - Symbol:
       max: "0.0019838809967041"
       avg: "0.0000033428150346"
       min: "0.0000019073486328"
   - String:
       max: "0.0019280910491943"
       avg: "0.0000037288846215"
       min: "0.0000019073486328"



also, don't forget that symbols are __never__ freed.


this is a severe memory leak:

   loop{ Time::now.to_f.to_s.intern }

this is not

   loop{ Time::now.to_f.to_s }


strings certainly play nicer with yaml as well.

regards.

-a
-- 
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy.  all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================


















a.rb