Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. [DllImport("foo", CallingConvention = CallingConvention.Cdecl)]
  2. static extern int GetHashNative(string str);
  3.  
  4. static int GetHashManaged(string str)
  5. {
  6. int hash = 0;
  7. if (string.IsNullOrEmpty(str))
  8. return hash;
  9.  
  10. for (int i = 0; i < str.Length; i++)
  11. hash = char.ToLower(str[i]) + (hash << 6) + (hash << 16) - hash;
  12.  
  13. return hash;
  14. }
  15.  
  16. static void Main()
  17. {
  18. string words = "qwertyuiopasdfghjklzxcvbnm_123";
  19. string w = "";
  20. Stopwatch sw = Stopwatch.StartNew();
  21. for (int i = 0; i < 1000; i++)
  22. {
  23. w += words[i % words.Length];
  24. var code = GetHashManaged(w);
  25. //var code = GetHashNative(w);
  26. }
  27. sw.Stop();
  28. System.Console.WriteLine("elapsed: " + sw.ElapsedMilliseconds);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement