1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
6 <meta name=
"generator" content=
"HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" />
7 <title>Tree Text Find Timing Test
</title>
8 <meta http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii" />
12 <h1>Tree-Based and Trie-Based Text
<tt>find
</tt> Find Timing
14 <h2><a name=
"description" id=
"description">Description
</a></h2>
15 <p>This test inserts a number of values with keys from an
16 arbitrary text ([
<a href=
"references.html#wickland96thirty">wickland96thirty
</a>]) into
17 a container, then performs a series of finds using
18 <tt>find
</tt>. It measures the average time for
<tt>find
</tt>
19 as a function of the number of values inserted.
</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/text_find_timing.cc"><tt>text_find_timing_test
</tt></a>
21 thirty_years_among_the_dead_preproc.txt
200 200 2100)
</p>
22 <h2><a name=
"purpose" id=
"purpose">Purpose
</a></h2>
23 <p>The test checks the effect of different underlying
25 <h2><a name=
"results" id=
"results">Results
</a></h2>
26 <p>Figures
<a href=
"#NTTG">NTTG
</a>,
<a href=
"#NTTM">NTTM
</a>,
27 and
<a href=
"#NTTG">NTTL
</a> show the results for the native,
28 tree-based, and trie-based types in
<a href=
"assoc_performance_tests.html#gcc"><u>g++
</u></a>,
<a href=
"assoc_performance_tests.html#local"><u>local
</u></a>, and
29 <a href=
"assoc_performance_tests.html#local"><u>local
</u></a>,
31 <div id=
"NTTG_res_div">
33 <div id=
"NTTG_random_int_find_find_timing_test_tree">
35 <div id=
"NTTG_Native_456_tree-based_456_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=
"NTTG" id=
"NTTG"><img src=
"random_int_find_find_timing_test_tree_gcc.png" alt=
"no image" /></a></h6>NTTG: Native, tree-based, 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 <a href=
"tree.html"><tt>tree
</tt></a>
40 with
<tt>Tag
</tt> =
<a href=
"splay_tree_tag.html"><tt>splay_tree_tag
</tt></a>
41 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
45 <a href=
"tree.html"><tt>tree
</tt></a>
46 with
<tt>Tag
</tt> =
<a href=
"ov_tree_tag.html"><tt>ov_tree_tag
</tt></a>
47 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
51 <tt>std::map
</tt></li>
54 <a href=
"tree.html"><tt>tree
</tt></a>
55 with
<tt>Tag
</tt> =
<a href=
"rb_tree_tag.html"><tt>rb_tree_tag
</tt></a>
56 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
59 </div><div style=
"width: 100%; height: 20px"></div></div>
62 <div id=
"NTTM_res_div">
64 <div id=
"NTTM_random_int_find_find_timing_test_tree">
66 <div id=
"NTTM_Native_456_tree-based_456_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=
"NTTM" id=
"NTTM"><img src=
"random_int_find_find_timing_test_tree_msvc.png" alt=
"no image" /></a></h6>NTTM: Native, tree-based, 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>
70 <a href=
"tree.html"><tt>tree
</tt></a>
71 with
<tt>Tag
</tt> =
<a href=
"splay_tree_tag.html"><tt>splay_tree_tag
</tt></a>
72 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
76 <a href=
"tree.html"><tt>tree
</tt></a>
77 with
<tt>Tag
</tt> =
<a href=
"ov_tree_tag.html"><tt>ov_tree_tag
</tt></a>
78 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
82 <tt>std::map
</tt></li>
85 <a href=
"tree.html"><tt>tree
</tt></a>
86 with
<tt>Tag
</tt> =
<a href=
"rb_tree_tag.html"><tt>rb_tree_tag
</tt></a>
87 , and
<tt>Node_Update
</tt> =
<a href=
"null_tree_node_update.html"><tt>null_tree_node_update
</tt></a>
90 </div><div style=
"width: 100%; height: 20px"></div></div>
93 <div id=
"NTTL_res_div">
95 <div id=
"NTTL_random_int_find_find_timing_test_tree">
97 <div id=
"NTTL_Native_456_tree-based_456_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=
"NTTL" id=
"NTTL"><img src=
"random_int_find_find_timing_test_tree_local.png" alt=
"no image" /></a></h6>NTTL: Native, tree-based, 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>
100 <h2><a name=
"observations" id=
"observations">Observations
</a></h2>
101 <p>For this setting, a splay tree (
<a href=
"tree.html"><tt>tree
</tt></a>
102 with
<tt>Tag =
</tt> <a href=
"splay_tree_tag.html"><tt>splay_tree_tag
</tt></a>)
103 does not do well. This is possibly due to two
106 <li>A splay tree is not guaranteed to be balanced
107 [
<a href=
"references.html#motwani95random">motwani95random
</a>].
108 If a splay tree contains
<i>n
</i> nodes, its
109 average root-leaf path can be
<i>m
>>
111 <li>Assume a specific root-leaf search path has
112 length
<i>m
</i>, and the search-target node has
113 distance
<i>m'
</i> from the root. A red-black
114 tree will require
<i>m +
1</i> comparisons to
115 find the required node; a splay tree will require
116 <i>2 m'
</i> comparisons. A splay tree,
117 consequently, can perform many more comparisons
118 than a red-black tree.
</li>
120 <p>An ordered-vector tree (
<a href=
"tree.html"><tt>tree
</tt></a>
121 with
<tt>Tag =
</tt> <a href=
"ov_tree_tag.html"><tt>ov_tree_tag
</tt></a>),
122 a red-black tree (
<a href=
"tree.html"><tt>tree
</tt></a>
123 with
<tt>Tag =
</tt> <a href=
"splay_tree_tag.html"><tt>rb_tree_tag
</tt></a>),
124 and the native red-black tree all share
125 approximately the same performance.
</p>
126 <p>An ordered-vector tree is slightly slower than
127 red-black trees, since it requires, in order to
128 find a key, more math operations than they do.
129 Conversely, an ordered-vector tree requires far
130 lower space than the others. ([
<a href=
"references.html#austern00noset">austern00noset
</a>],
131 however, seems to have an implementation that is
132 also faster than a red-black tree).
</p>
133 <p>A PATRICIA trie (
<a href=
"trie.html"><tt>trie
</tt></a>
134 with
<tt>Tag =
</tt> <a href=
"pat_trie_tag.html"><tt>pat_trie_tag
</tt></a>)
135 has good look-up performance, due to its large
136 fan-out in this case. In this setting, a PATRICIA
137 trie has lookup performance comparable to a hash
138 table (see
<a href=
"hash_text_find_find_timing_test.html">Hash-Based
139 Text
<tt>find
</tt> Find Timing Test
</a>), but it is
140 order preserving. This is not that surprising,
141 since a large fan-out PATRICIA trie works like a
142 hash table with collisions resolved by a sub-trie.
143 A large fan-out PATRICIA trie does not do well on
144 modifications (see
<a href=
"tree_text_insert_timing_test.html">Tree-Based and
145 Trie-Based Text Insert Timing Test
</a>). It is
146 possibly beneficial to semi-static settings,
148 <p><a href=
"assoc_performance_tests.html#tree_like_based_types">
149 Observations::Tree-Like-Based Container Types
</a>
150 summarizes some observations on tree-based and
151 trie-based containers.
</p>