[Mono-devel-list] String::GetHashCode speedup
Ben Maurer
bmaurer at users.sourceforge.net
Tue Feb 24 23:03:29 EST 2004
Hey guys,
I transformed String.GetHashCode into a managed function. It works
fairly well, even for somewhat large strings:
Len +--- Old ---+--- New ---+
2 | .150 s | .042 s |
8 | .223 s | .091 s |
14 | .279 s | .174 s |
20 | .309 s | .226 s |
26 | .344 s | .287 s |
32 | .376 s | .333 s |
38 | .408 s | .401 s |
44 | .449 s | .471 s |
50 | .482 s | .528 s |
56 | .514 s | .605 s |
62 | .548 s | .747 s |
68 | .580 s | .645 s |
74 | .614 s | .701 s |
80 | .648 s | .749 s |
86 | .685 s | .860 s |
92 | .715 s | .937 s |
98 | .751 s | .934 s |
----+-----------+-----------+
So it appears the break-even point here is at ~ 38 chars. Also, when I
ran the GetHashCode function on MS's runtime, it was always faster than
MS's String.GetHashCode function. So, it seems that with a little bit of
JIT work, we could push this break-even point much higher, or make it so
we always win.
In the process, I discovered that constructs such as:
fixed (char* foo = my_string) { ... }
Call a function that basically gets a fixed value. I have attached a
patch to mini that will embed the constant in the emitted code. This
gives a nice speedup to anyone using the construct. Before, we were
working around this in String.cs by doing
fixed (char* foo = &s.start_char) { ... }
However, that is absurdly messy ;-). Also, you obviously cant do it
outside of String.
-- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: corlib-string-managed-ghc.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040224/486580cd/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mini-intrinsic-getoffsettostringdata.patch
Type: text/x-patch
Size: 1048 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040224/486580cd/attachment-0001.bin
More information about the Mono-devel-list
mailing list