[Mono-bugs] [Bug 405052] Performance of 16-bit operation
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Jun 30 13:03:09 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=405052
User msafar at novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=405052#c2
Marek Safar <msafar at novell.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |NEW
Info Provider|msafar at novell.com |
--- Comment #2 from Marek Safar <msafar at novell.com> 2008-06-30 11:03:09 MDT ---
Ouch, I forget to attach the test program.
using System;
using System.Diagnostics;
namespace Test
{
class Program
{
static void Main ()
{
Stopwatch sw = new Stopwatch ();
sw.Start ();
int r = 0;
for (int i = 0; i < 20000000; ++i) {
r = GetHashCode ("a");
r = GetHashCode ("abc");
r = GetHashCode ("abcd");
r = GetHashCode ("abcdef");
r = GetHashCode ("abcdefghijklm");
r = GetHashCode ("abcdefghij");
}
sw.Stop ();
Console.WriteLine (sw.Elapsed);
Console.WriteLine (r);
}
public static unsafe int GetHashCode (string s)
{
fixed (char* c = s) {
char* cc = c;
char* end = cc + s.Length - 1;
int h = 23;
while (cc < end) {
h = (h << 5) * 37 + *cc;
h = (h << 5) * 37 + cc [1];
cc += 2;
}
++end;
if (cc < end)
h = (h << 5) * 37 + *cc;
return h;
}
}
}
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list