Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <tscmarks.h>
  2. #include <vppinfra/bihash_24_8.h>
  3. #include <vppinfra/bihash_template.h>
  4. #include <vppinfra/mem.h>
  5.  
  6. #include <vppinfra/bihash_template.c>
  7.  
  8. #define NUM_BUCKETS (1 << 24)
  9. #define N_ELTS (100 * 1000 * 1000)
  10. #define MEM_SIZE (16ULL << 30)
  11.  
  12. BVT (clib_bihash) test_table;
  13.  
  14. typedef union
  15. {
  16. u16 words[24];
  17. u64 qwords[6];
  18. BVT (clib_bihash_kv) kv;
  19. } foo_key_t;
  20.  
  21. static inline void
  22. calc_key (foo_key_t *k, u32 x)
  23. {
  24. #ifdef BAD
  25. k->words[0] = x >> 16;
  26. k->words[1] = x & 0xffff;
  27. k->words[2] = x >> 16;
  28. k->words[3] = x & 0xffff;
  29. #else
  30. u64 a = x >> 16;
  31. u64 b = x & 0xffff;
  32. k->qwords[0] = a | b << 16 | a << 32 | b << 48;
  33. #endif
  34.  
  35. k->qwords[1] = b | a << 16 | b << 32 | a << 48;
  36. k->qwords[2] = a | b << 16 | a << 32 | b << 48;
  37. // k->qwords[3] = x;
  38. // k->qwords[4] = x;
  39. // k->qwords[5] = x;
  40. }
  41.  
  42. void
  43. key_add (u64 k, u64 v)
  44. {
  45. foo_key_t fk;
  46. calc_key (&fk, k);
  47. fk.kv.value = v;
  48. BV (clib_bihash_add_del) (&test_table, &fk.kv, 1);
  49. }
  50.  
  51. static inline uword
  52. key_search (u64 k)
  53. {
  54. foo_key_t fk;
  55. u64 hash;
  56. calc_key (&fk, k);
  57. hash = BV (clib_bihash_hash) (&fk.kv);
  58. BV (clib_bihash_search_inline_with_hash) (&test_table, hash, &fk.kv);
  59. return fk.kv.value;
  60. }
  61.  
  62. #define CNT (8192)
  63.  
  64. int
  65. main (int argc, char *argv[])
  66. {
  67. int i;
  68. clib_mem_init (0, 8ULL << 20);
  69.  
  70. clib_warning ("init");
  71. BV (clib_bihash_init) (&test_table, "test", NUM_BUCKETS, MEM_SIZE);
  72.  
  73. for (i = 1; i <= N_ELTS; i++)
  74. {
  75. key_add (i, i * 10);
  76. if (i % 1000000 == 0)
  77. fformat (stderr, "\n%u elts\n%U\n", i, BV (format_bihash),
  78. &test_table, 0);
  79. }
  80.  
  81. clib_warning ("%U", BV (format_bihash), &test_table, 0);
  82. clib_warning ("rv %u", key_search (1024));
  83.  
  84. while (1)
  85. {
  86. tsc_mark ("start");
  87. for (int i = 1; i < CNT; i++)
  88. {
  89. uword rv;
  90. rv = key_search (i);
  91. if (rv != i * 10)
  92. fformat (stderr, "i %u rv %u\n", i, rv);
  93. }
  94. tsc_mark ("end");
  95. tsc_print (1, CNT);
  96. }
  97. }
Add Comment
Please, Sign In to add comment