in reply to Re^2: When should I use a dispatch table?
in thread When should I use a dispatch table?

The values are integers only because it made enumerating easier. The string equality is intentional. The 1 .. n could have as easily been 'a' .. 'z'.

OK. But doesn't that make the ifelse code slower because it has to stringify and/or do string comparison, while the hash can do an integer comparison?

I did try another test. Since the values were integers I replaced the dispatch table hash with an array and performance improved, but not enough to catch the ifelse. I am still quite confused.

  • Comment on Re^3: When should I use a dispatch table?

Replies are listed 'Best First'.
Re^4: When should I use a dispatch table?
by Limbic~Region (Chancellor) on Dec 01, 2006 at 00:18 UTC
    traveler,
    Stringification happens both in the hash table and in the if/elsif equality test so it is fair. The eq forces string context and so do hash keys. Anyone that has tried to use a reference as a hash key can attest to that.

    Cheers - L~R