PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/libstdc++-v3/doc/html/ext/pb_ds/hash_zlob_random_int_find_find_timing_test.html

https://bitbucket.org/pizzafactory/pf-gcc
HTML | 163 lines | 162 code | 1 blank | 0 comment | 0 complexity | 39c19e33a3f4c9c2777818e87fba003d MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta name="generator" content="HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" />
  6. <title>Hash Skewed Distribution Memory Use Test</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
  8. </head>
  9. <body>
  10. <div id="page">
  11. <h1>Hash-Based Skewed-Distribution Random-Integer <tt>find</tt>
  12. Find Timing Test</h1>
  13. <h2><a name="description" id="description">Description</a></h2>
  14. <p>This test inserts a number of values with a markedly
  15. non-uniform i.i.d. integer keys into a container, then performs
  16. a series of finds using <tt>find</tt> . It measures the average
  17. time for <tt>find</tt> as a function of the number of values in
  18. the containers. The keys are generated as follows. First, a
  19. uniform integer is created; it is then shifted left 8 bits.</p>
  20. <p>(The test was executed with <a href="http://gcc.gnu.org/viewcvs/*checkout*/trunk/libstdc%2B%2B-v3/testsuite/performance/ext/pb_ds/hash_zlob_random_int_find_timing.cc"><tt>hash_zlob_random_int_find_timing_test</tt></a>
  21. 200 200 2100)</p>
  22. <h2><a name="purpose" id="purpose">Purpose</a></h2>
  23. <p>The test checks the effect of different range-hashing
  24. functions and trigger policies (see <a href="hash_based_containers.html#hash_policies">Design::Associative
  25. Containers::Hash-Based Containers::Hash Policies</a> and
  26. <a href="hash_based_containers.html#resize_policies">Design::Associative
  27. Containers::Hash-Based Containers::Resize Policies</a>).</p>
  28. <h2><a name="results" id="results">Results</a></h2>
  29. <p>Figures <a href="#NHG">NHG</a>, <a href="#NHM">NHM</a>, and
  30. <a href="#NHL">NHL</a> show the results for various hash-based
  31. associative-containers in <a href="assoc_performance_tests.html#gcc"><u>g++</u></a>, <a href="assoc_performance_tests.html#msvc"><u>MSVC++</u></a>, and
  32. <a href="assoc_performance_tests.html#local"><u>local</u></a>,
  33. respectively.</p>
  34. <div id="NHG_res_div">
  35. <div id="NHG_gcc">
  36. <div id="NHG_hash_zlob_random_int_find_timing_test">
  37. <div id="NHG_assoc">
  38. <div id="NHG_Skewed-distribution_random_int_find_timing_test_using__tt_find_455tt_"><div style="border-style: dotted; border-width: 1px; border-color: lightgray"><h6 class="c1"><a name="NHG" id="NHG"><img src="hash_zlob_random_int_find_timing_test_gcc.png" alt="no image" /></a></h6>NHG: Skewed-distribution random int find timing test using <tt>find</tt> - <a href="assoc_performance_tests.html#gcc">g++</a><p>In the above figure, the names in the legends have the following meaning:</p>
  39. <ol>
  40. <li>
  41. cc_hash_mask_exp_nea_lc_1div8_1div1_nsth_map-
  42. <a href="cc_hash_table.html"><tt>cc_hash_table</tt></a>
  43. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mask_range_hashing.html"><tt>direct_mask_range_hashing</tt></a>
  44. , and <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  45. with <tt>Size_Policy</tt> = <a href="hash_exponential_size_policy.html"><tt>hash_exponential_size_policy</tt></a>
  46. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  47. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/1</i></li>
  48. <li>
  49. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map-
  50. <a href="gp_hash_table.html"><tt>gp_hash_table</tt></a>
  51. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mod_range_hashing.html"><tt>direct_mod_range_hashing</tt></a>
  52. , <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  53. with <tt>Size_Policy</tt> = <a href="hash_prime_size_policy.html"><tt>hash_prime_size_policy</tt></a>
  54. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  55. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/2</i>, and <tt>Probe_Fn</tt> = <a href="quadratic_probe_fn.html"><tt>quadratic_probe_fn</tt></a>
  56. </li>
  57. <li>
  58. n_hash_map_ncah-
  59. <tt>std::tr1::unordered_map</tt> with <tt>cache_hash_code</tt> = <tt><b>false</b></tt></li>
  60. <li>
  61. cc_hash_mod_prime_nea_lc_1div8_1div1_nsth_map-
  62. <a href="cc_hash_table.html"><tt>cc_hash_table</tt></a>
  63. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mod_range_hashing.html"><tt>direct_mod_range_hashing</tt></a>
  64. , and <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  65. with <tt>Size_Policy</tt> = <a href="hash_prime_size_policy.html"><tt>hash_prime_size_policy</tt></a>
  66. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  67. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/1</i></li>
  68. </ol>
  69. </div><div style="width: 100%; height: 20px"></div></div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. <div id="NHM_res_div">
  75. <div id="NHM_msvc">
  76. <div id="NHM_hash_zlob_random_int_find_timing_test">
  77. <div id="NHM_assoc">
  78. <div id="NHM_Skewed-distribution_random_int_find_timing_test_using__tt_find_455tt_"><div style="border-style: dotted; border-width: 1px; border-color: lightgray"><h6 class="c1"><a name="NHM" id="NHM"><img src="hash_zlob_random_int_find_timing_test_msvc.png" alt="no image" /></a></h6>NHM: Skewed-distribution random int find timing test using <tt>find</tt> - <a href="assoc_performance_tests.html#msvc">msvc++</a><p>In the above figure, the names in the legends have the following meaning:</p>
  79. <ol>
  80. <li>
  81. n_hash_map_ncah-
  82. <tt>stdext::hash_map</tt></li>
  83. <li>
  84. cc_hash_mask_exp_nea_lc_1div8_1div1_nsth_map-
  85. <a href="cc_hash_table.html"><tt>cc_hash_table</tt></a>
  86. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mask_range_hashing.html"><tt>direct_mask_range_hashing</tt></a>
  87. , and <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  88. with <tt>Size_Policy</tt> = <a href="hash_exponential_size_policy.html"><tt>hash_exponential_size_policy</tt></a>
  89. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  90. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/1</i></li>
  91. <li>
  92. gp_hash_mod_quadp_prime_nea_lc_1div8_1div2_nsth_map-
  93. <a href="gp_hash_table.html"><tt>gp_hash_table</tt></a>
  94. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mod_range_hashing.html"><tt>direct_mod_range_hashing</tt></a>
  95. , <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  96. with <tt>Size_Policy</tt> = <a href="hash_prime_size_policy.html"><tt>hash_prime_size_policy</tt></a>
  97. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  98. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/2</i>, and <tt>Probe_Fn</tt> = <a href="quadratic_probe_fn.html"><tt>quadratic_probe_fn</tt></a>
  99. </li>
  100. <li>
  101. cc_hash_mod_prime_nea_lc_1div8_1div1_nsth_map-
  102. <a href="cc_hash_table.html"><tt>cc_hash_table</tt></a>
  103. with <tt>Comb_Hash_Fn</tt> = <a href="direct_mod_range_hashing.html"><tt>direct_mod_range_hashing</tt></a>
  104. , and <tt>Resize_Policy</tt> = <a href="hash_standard_resize_policy.html"><tt>hash_standard_resize_policy</tt></a>
  105. with <tt>Size_Policy</tt> = <a href="hash_prime_size_policy.html"><tt>hash_prime_size_policy</tt></a>
  106. , and <tt>Trigger_Policy</tt> = <a href="hash_load_check_resize_trigger.html"><tt>hash_load_check_resize_trigger</tt></a>
  107. with <i>&alpha;<sub>min</sub></i> = <i>1/8</i> and <i>&alpha;<sub>max</sub></i> = <i>1/1</i></li>
  108. </ol>
  109. </div><div style="width: 100%; height: 20px"></div></div>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. <div id="NHL_res_div">
  115. <div id="NHL_local">
  116. <div id="NHL_hash_zlob_random_int_find_timing_test">
  117. <div id="NHL_assoc">
  118. <div id="NHL_Skewed-distribution_random_int_find_timing_test_using__tt_find_455tt_"><div style = "border-style: dotted; border-width: 1px; border-color: lightgray"><h6 class="c1"><a name="NHL" id= "NHL"><img src="hash_zlob_random_int_find_timing_test_local.png" alt="no image" /></a></h6>NHL: Skewed-distribution random int find timing test using <tt>find</tt> - <a href = "assoc_performance_tests.html#local">local</a></div><div style = "width: 100%; height: 20px"></div></div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <h2><a name="observations" id="observations">Observations</a></h2>
  124. <p>In this setting, the keys' distribution is so skewed that
  125. the unerlying hash-table type affects performance marginally.
  126. (This is in contrast with <a href="hash_text_find_find_timing_test.html">Hash-Based Text
  127. <tt>find</tt> Find Timing Test</a> , <a href="hash_random_int_find_find_timing_test.html">Hash-Based
  128. Random-Integer <tt>find</tt> Find Timing Test</a> , <a href="hash_random_int_subscript_find_timing_test.html">Hash-Based
  129. Random-Integer Subscript Find Timing Test</a> and <a href="hash_random_int_subscript_insert_timing_test.html">Hash-Based
  130. Random-Integer Subscript Insert Timing Test</a> .)</p>
  131. <p>The range-hashing scheme affects performance dramatically. A
  132. mask-based range-hashing scheme effectively maps all values
  133. into the same bucket. Access degenerates into a search within
  134. an unordered linked-list. In Figures <a href="#NHG">NHG</a> and
  135. <a href="#NHM">NHM</a> , it should be noted that
  136. <tt>std::tr1::unordered_map</tt> and <tt>stdext::hash_map</tt>
  137. are hard-wired currently to mod-based and mask-based schemes,
  138. respectively.</p>
  139. <p>When observing the settings of this test, it is apparent
  140. that the keys' distribution is far from natural. One might ask
  141. if the test is not contrived to show that, in some cases,
  142. mod-based range hashing does better than mask-based range
  143. hashing. This is, in fact just the case. We did not encounter a
  144. more natural case in which mod-based range hashing is better.
  145. In our opnion, real-life key distributions are handled better
  146. with an appropriate hash function and a mask-based
  147. range-hashing function. (<a href="http://gcc.gnu.org/viewcvs/*checkout*/trunk/libstdc%2B%2B-v3/testsuite/ext/pb_ds/example/hash_shift_mask.cc"><tt>shift_mask.cc</tt></a>
  148. shows an example of handling this a-priori known skewed
  149. distribution with a mask-based range-hashing function). If hash
  150. performance is bad, a <i>&Chi;<sup>2</sup></i> test can be used
  151. to check how to transform it into a more uniform
  152. distribution.</p>
  153. <p>For this reason, <tt>pb_ds</tt>'s default range-hashing
  154. function is mask-based.</p>
  155. <p><a href="assoc_performance_tests.html#hash_based_types">Observations::Hash-Based
  156. Container Types</a> summarizes some observations on hash-based
  157. containers; <a href="assoc_performance_tests.html#hash_based_policies">Observations::Hash-Based
  158. Containers' Policies</a> summarizes some observations on
  159. hash-based containers' policies.</p>
  160. </div>
  161. </body>
  162. </html>