| Store | Cart

Re: [TCLCORE] Upgrade of Tcl's String Hash Algorithm

From: Gustaf Neumann <neum...@wu.ac.at>
Tue, 09 Feb 2010 17:15:12 +0100
Am 09.02.10 02:47, schrieb Donal K. Fellows:
> On 08/02/2010 18:45, Eric Melski wrote:>> That's very impressive, but with only three hash entries you can hardly>> say that's a representative test case.
...
> FWIW, with a focussed test that *just* does comparison of the hashing> speed (see attached; the contents of the two hashing functions were> copied directly from HashStringKey in Tcl 8.5 and the HEAD) we find that> on x86 the old algorithm is indeed faster. 
indeed,  the attached program shows me that the hashing speed of the
old function is constantly faster than FNV (when compiled with
-Os like Tcl, intel mac, 64bit, 10.6.2).

old: 2137177 us    (1517306493d)
new: 2296518 us    (3684793705d)

(i just added an outer loop with 500 iterations to obtain more
precise timings). By using the function in tcl 8.5.7 for HashStringKey(),
i could not get the 15% speedup, but i see a rather larger slowdown
for the first test.

proc foo {} {set x(foobar) [set x(barfoo) [set x(ballyhoo) 1]];return}
puts [time {time { foo } 10000} 1000]
proc foo {} {set x [set y [set z 1]]; return}
puts [time {time { foo } 10000} 1000]

# classic
# 9105.318082 microseconds per iteration
# 4686.419043 microseconds per iteration

# fnv
# 9367.280143 microseconds per iteration
# 4684.1961710000005 microseconds per iteration

Btw, the old function could be made slightly faster by avoiding one
incr operation

     for (c = *string ; c ; c = *++string) {
         result += (result<<3) + c;
     }

The output of Donal showing the buckets indicates certainly
that FNV leads to less collisions. However, since from my experience,
we have in tcl many hash tables with only a few items.
I would not be surprised if most programs run rather slower
with FNV than with the old tcl hash function.

maybe, some handcoded inline assembly could speed up the function.

-gn


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
Donal K. Fellows Feb 07, 2010 09:36 am
Eric Melski Feb 08, 2010 06:40 am
Donal K. Fellows Feb 08, 2010 11:21 am
Eric Melski Feb 08, 2010 06:45 pm
Donal K. Fellows Feb 09, 2010 01:47 am
Larry McVoy Feb 09, 2010 02:42 am
Colin McCormack Feb 09, 2010 01:05 pm
Larry McVoy Feb 09, 2010 03:48 pm
Colin McCormack Feb 09, 2010 11:14 pm
Gustaf Neumann Feb 09, 2010 04:15 pm
Donal K. Fellows Feb 10, 2010 12:38 am
Lars Hellström Feb 14, 2010 10:56 pm
Larry McVoy Feb 15, 2010 03:20 am
Donal K. Fellows Feb 15, 2010 10:02 pm
Tom Jackson Feb 15, 2010 08:55 pm
Lars Hellström Feb 15, 2010 11:53 pm
Donal K. Fellows Feb 16, 2010 11:56 am
Colin McCormack Feb 16, 2010 01:01 pm
Eric Melski Feb 09, 2010 11:35 pm
Alexandre Ferrieux Feb 11, 2010 12:08 am
Alexandre Ferrieux Feb 12, 2010 04:57 pm
Gustaf Neumann Feb 14, 2010 04:58 pm
Donal K. Fellows Feb 14, 2010 11:54 pm
Gustaf Neumann Feb 16, 2010 03:25 pm
Donal K. Fellows Feb 16, 2010 04:45 pm
Gustaf Neumann Feb 17, 2010 11:04 am
Kristoffer Lawson Feb 17, 2010 11:18 am
Tom Jackson Feb 16, 2010 06:30 pm
Donal K. Fellows Feb 16, 2010 10:44 pm
Gustaf Neumann Feb 17, 2010 11:49 am
Donal K. Fellows Feb 16, 2010 10:36 pm
John Ousterhout Feb 15, 2010 04:56 am
Donal K. Fellows Feb 15, 2010 03:14 pm
Colin McCormack Feb 16, 2010 01:16 pm
Larry McVoy Feb 15, 2010 04:16 pm
Tom Jackson Feb 18, 2010 09:31 pm
Tom Jackson Feb 17, 2010 06:41 pm
Donal K. Fellows Feb 18, 2010 09:23 am
Gustaf Neumann Feb 18, 2010 12:23 pm
Tom Jackson Feb 17, 2010 01:36 am
Donal K. Fellows Feb 17, 2010 11:56 am
Tom Jackson Feb 16, 2010 09:30 am
Joe English Feb 08, 2010 07:56 pm
Donal K. Fellows Feb 08, 2010 09:56 pm
Messages in this thread