]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/performance/25_algorithms/sort_heap.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / performance / 25_algorithms / sort_heap.cc
1 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 #include <vector>
19 #include <algorithm>
20 #include <testsuite_performance.h>
21
22 int main()
23 {
24 using namespace __gnu_test;
25
26 time_counter time;
27 resource_counter resource;
28
29 const int max_size = 10000000;
30
31 std::vector<int> v(max_size);
32
33 for (int i = 0; i < max_size; ++i)
34 v[i] = -i;
35
36 start_counters(time, resource);
37 std::make_heap(v.begin(), v.end());
38 stop_counters(time, resource);
39
40 report_performance(__FILE__, "make_heap_reverse", time, resource);
41 clear_counters(time, resource);
42
43 for (int i = 0; i < max_size; ++i)
44 v[i] = i;
45
46 start_counters(time, resource);
47 std::make_heap(v.begin(), v.end());
48 stop_counters(time, resource);
49
50 report_performance(__FILE__, "make_heap_forwards", time, resource);
51 clear_counters(time, resource);
52
53 // a simple psuedo-random series which does not rely on rand() and friends
54 v[0] = 0;
55 for (int i = 1; i < max_size; ++i)
56 v[i] = (v[i-1] + 110211473) * 745988807;
57
58 start_counters(time, resource);
59 std::make_heap(v.begin(), v.end());
60 stop_counters(time, resource);
61
62 report_performance(__FILE__, "make_heap_random", time, resource);
63
64
65 start_counters(time, resource);
66 std::sort_heap(v.begin(), v.end());
67 stop_counters(time, resource);
68
69 report_performance(__FILE__, "sort_heap", time, resource);
70 clear_counters(time, resource);
71
72 return 0;
73 }