Guest User

Untitled

a guest
Oct 7th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. typedef unsigned int uint32;
  6.  
  7. #include "pg_crc.h"
  8. #include "fnv.h"
  9. #include "xxhash.h"
  10.  
  11. #define VALUES 2000000000
  12.  
  13. void main() {
  14.  
  15. int i;
  16. int result = FNV0_32_INIT;
  17. void * state;
  18.  
  19. struct timeval start, end;
  20.  
  21. gettimeofday(&start, NULL);
  22. for (i = 0; i < VALUES; i++) {
  23. result = fnv_32_buf(&i, 4, result);
  24. }
  25. gettimeofday(&end, NULL);
  26.  
  27. printf("FNV duration = %.3f\n", (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0);
  28.  
  29. gettimeofday(&start, NULL);
  30. for (i = 0; i < VALUES; i++) {
  31. result = fnv_32a_buf(&i, 4, result);
  32. }
  33. gettimeofday(&end, NULL);
  34.  
  35. printf("FNVa duration = %.3f\n", (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0);
  36.  
  37. gettimeofday(&start, NULL);
  38. for (i = 0; i < VALUES; i++) {
  39. result = jenkins_one_at_a_time_hash(&i, 4);
  40. }
  41. gettimeofday(&end, NULL);
  42.  
  43. printf("jenkins duration = %.3f\n", (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0);
  44.  
  45. gettimeofday(&start, NULL);
  46. for (i = 0; i < VALUES; i++) {
  47. INIT_CRC32(result);
  48. COMP_CRC32(result, &i, 4);
  49. FIN_CRC32(result);
  50. }
  51. gettimeofday(&end, NULL);
  52.  
  53. printf("crc32 duration = %.3f\n", (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0);
  54.  
  55. gettimeofday(&start, NULL);
  56. for (i = 0; i < VALUES; i++) {
  57. state = XXH32_init(result);
  58. XXH32_update(state, &i, 4);
  59. XXH32_digest(state);
  60. }
  61. gettimeofday(&end, NULL);
  62.  
  63. printf("xxhash duration = %.3f\n", (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0);
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment