1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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)
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.
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/>.
20 #include <testsuite_performance.h>
24 __gnu_test::time_counter time
;
25 __gnu_test::resource_counter resource
;
29 template<typename Dist
, typename Engine
>
30 void do_fill_with_uniform_ints(std::string name
, Dist
& d
, Engine
& e
)
33 using counters::resource
;
35 std::vector
<typename
Dist::result_type
> r
;
38 const auto suffix
= "-e" + std::to_string((int)std::log10(n
));
41 start_counters(time
, resource
);
44 stop_counters(time
, resource
);
45 report_performance(__FILE__
, name
+suffix
, time
, resource
);
46 clear_counters(time
, resource
);
50 start_counters(time
, resource
);
51 d
.__generate(begin(r
), end(r
), e
);
52 stop_counters(time
, resource
);
53 report_performance(__FILE__
, name
+"-range"+suffix
, time
, resource
);
54 clear_counters(time
, resource
);
58 template<typename Engine
>
59 void fill_with_uniform_ints(std::string name
, Engine
& e
)
61 using Dist
= std::uniform_int_distribution
<typename
Engine::result_type
>;
62 using param_type
= typename
Dist::param_type
;
64 unsigned maxima
[]{6, 10, 32, 100, 1000, 1024, (1<<16)-1, 1<<16, 1<<20, -1u};
65 for (auto hi
: maxima
)
67 Dist
dist(param_type
{0, hi
});
69 s
<< name
<< "-uniform_int-" << (dist
.max() - dist
.min());
70 do_fill_with_uniform_ints(s
.str(), dist
, e
);
79 fill_with_uniform_ints("mt19937", mt
);
81 fill_with_uniform_ints("mt19937_64", mt64
);
83 // Same as std::mt19937 but using uint32_t not uint_fast32_t for result_type
84 using mt19937_32
= std::mersenne_twister_engine
<uint32_t, 32, 624, 397, 31,
85 0x9908b0df, 11, 0xffffffff,
87 0xefc60000, 18, 1812433253>;
89 fill_with_uniform_ints("mt19937_32", mt32
);
91 std::minstd_rand0 lcg
;
92 fill_with_uniform_ints("minstd_rand0", lcg
);
94 // Same as std::minstd_rand0 but using uint32_t not uint_fast32_t
95 using minstd_rand0_32
= std::linear_congruential_engine
<uint32_t, 48271, 0,
97 minstd_rand0_32 lcg_32
;
98 fill_with_uniform_ints("minstd_rand0_32", lcg_32
);