From 21c332dc936d8008a3c959ce16899b97d9afe245 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 14 Jan 2005 21:09:38 +0000 Subject: [PATCH] re PR libstdc++/19422 (assoc. containers: ctor taking range is O(n log n) even if the range is sorted) 2005-01-14 Paolo Carlini PR libstdc++/19422 * include/bits/stl_tree.h (_Rb_tree<>::insert_equal(_II, _II), _Rb_tree<>::insert_unique(_II, _II)): Use insert_equal (insert_unique, respectively) with hint (end()). * testsuite/performance/23_containers/set_create_from_sorted.cc: New. From-SVN: r93663 --- libstdc++-v3/ChangeLog | 8 ++ libstdc++-v3/include/bits/stl_tree.h | 4 +- .../23_containers/set_create_from_sorted.cc | 83 +++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/performance/23_containers/set_create_from_sorted.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9aa1d6b8cd7..00deb297d0c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2005-01-14 Paolo Carlini + + PR libstdc++/19422 + * include/bits/stl_tree.h (_Rb_tree<>::insert_equal(_II, _II), + _Rb_tree<>::insert_unique(_II, _II)): Use insert_equal (insert_unique, + respectively) with hint (end()). + * testsuite/performance/23_containers/set_create_from_sorted.cc: New. + 2005-01-13 Geoffrey Keating * configure.host (darwin): On darwin8 or later, no need to build diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index e2442f09c46..a49b898e16b 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -986,7 +986,7 @@ namespace std insert_equal(_II __first, _II __last) { for (; __first != __last; ++__first) - insert_equal(*__first); + insert_equal(end(), *__first); } template +#include +#include +#include +#include + +// adjust for your setup +static const unsigned max_size = 1000000; // avoid excessive swap file use! +static const unsigned iterations = 10; // make results less random while +static const unsigned step = 50000; // keeping the total time reasonable + +// libstdc++/19422 +int main() +{ + using namespace std; + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + typedef set the_set; + typedef list the_list; + + vector v(max_size, 0); + for (unsigned i = 0; i != max_size; ++i) + v[i] = i; // initialize sorted array + + report_header(__FILE__, "set:"); + for (unsigned count = step; count <= max_size; count += step) + { + ostringstream oss; + oss << count; + + // measure set construction time + start_counters(time, resource); + for (unsigned i = 0; i != iterations; ++i) + the_set(v.begin(), v.begin() + count); + stop_counters(time, resource); + report_performance(__FILE__, oss.str(), time, resource); + clear_counters(time, resource); + } + + report_header(__FILE__, "list:"); + for (unsigned count = step; count <= max_size; count += step) + { + ostringstream oss; + oss << count; + + // measure list construction time (surely linear in count) + start_counters(time, resource); + for (unsigned i = 0; i != iterations; ++i) + the_list(v.begin(), v.begin() + count); + stop_counters(time, resource); + report_performance(__FILE__, oss.str(), time, resource); + clear_counters(time, resource); + } +} -- 2.30.2