From: Paolo Carlini Date: Fri, 14 Jan 2005 21:09:38 +0000 (+0000) Subject: re PR libstdc++/19422 (assoc. containers: ctor taking range is O(n log n) even if... X-Git-Tag: releases/gcc-4.0.0~1572 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21c332dc936d8008a3c959ce16899b97d9afe245;p=thirdparty%2Fgcc.git 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9aa1d6b8cd73..00deb297d0c1 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 e2442f09c468..a49b898e16bc 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); + } +}