Created
July 28, 2017 12:21
-
-
Save EgorBo/71c3683b586103517f9b5280593293e5 to your computer and use it in GitHub Desktop.
test.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment