Suggestion to improve phobos std.string.icmp function
Chad J
gamerChad at _spamIsBad_gmail.com
Mon Jul 17 00:19:35 PDT 2006
I am modifying gphobos to support WinCE, and it just so happens that
memicmp (used in std.string.icmp) is not available with the cegcc/newlib
libraries that I have at my disposal for WinCE. Then I noticed that
memicmp is only used on Win32 platforms. Unix platforms (linux in dmd
phobos) seem to have a perfectly good fully cross-platform alternative
written in D. So my first suggestion is this: ditch the C dependency
and what seems like an unnecessary version statement.
Then I started thinking, the memicmp thing might be an optimization or
something if memicmp can outperform the D alternative. So I decided to
test it out. I also thought it would be fun to try and write a version
that is even more optimized than either of the two before, and I think
I've succeeded.
The source file should be attached. I compiled with dmd and build using
the line 'build main.d -clean -O -inline -release -ofmain'. I've tried
without -release and it does change things (for me); not sure if Phobos
is usually compiled with -release.
This is what my main.d gave me on the slower of the two computers I
tested on (AMD Athlon XP 2600+ with WinXP):
The following tests involve a worst-case scenario where strings that
have highly divergent capitalization are compared.
739947 - current Phobos on Win32 systems using memicmp function.
962118 - current Phobos on *nix systems using D implementation.
482975 - possible new implementation.
Begin tests where the strings have identical capitalization already.
410813 - current Phobos on Win32 systems using memicmp function.
410238 - current Phobos on *nix systems using D implementation.
238644 - possible new implementation.
This is what my main.d gave me on the other computer I tested on (AMD
Turion 64 MT40 with WinXP):
The following tests involve a worst-case scenario where strings that
have highly divergent capitalization are compared.
825528 - current Phobos on Win32 systems using memicmp function.
678905 - current Phobos on *nix systems using D implementation.
442500 - possible new implementation.
Begin tests where the strings have identical capitalization already.
355304 - current Phobos on Win32 systems using memicmp function.
369101 - current Phobos on *nix systems using D implementation.
309204 - possible new implementation.
I ran it a few more times on each system and the numbers stay pretty
consistant. The downside of the new implementation is that it takes an
extra 256 bytes at runtime for a table lookup, and the table is
generated at starttime. Anyhow, I suggest/propose that this new routine
(icmpNew in the source file, would be renamed icmp) replace icmp in
std.string.
Also, the table it uses might be able to speedup other functions there
(like tolower! hehe) but I haven't looked into that, and I probably
won't unless someone asks me to or I run into another missing dependency
in gphobos.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20060717/beb70f12/attachment.ksh>
More information about the Digitalmars-d
mailing list