Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DllImport("foo", CallingConvention = CallingConvention.Cdecl)]
- static extern int GetHashNative(string str);
- static int GetHashManaged(string str)
- {
- int hash = 0;
- if (string.IsNullOrEmpty(str))
- return hash;
- for (int i = 0; i < str.Length; i++)
- hash = char.ToLower(str[i]) + (hash << 6) + (hash << 16) - hash;
- return hash;
- }
- static void Main()
- {
- string words = "qwertyuiopasdfghjklzxcvbnm_123";
- string w = "";
- Stopwatch sw = Stopwatch.StartNew();
- for (int i = 0; i < 1000; i++)
- {
- w += words[i % words.Length];
- var code = GetHashManaged(w);
- //var code = GetHashNative(w);
- }
- sw.Stop();
- System.Console.WriteLine("elapsed: " + sw.ElapsedMilliseconds);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement