@@ -17,7 +17,8 @@ void Benchmark::add_benchmark(Benchmark *benchmark) {
17
17
benchmarks.push_back (benchmark);
18
18
}
19
19
20
- BenchmarkResult reduce_results (cpp::array<BenchmarkResult, 1024 > &results) {
20
+ BenchmarkResult
21
+ reduce_results (const cpp::array<BenchmarkResult, 1024 > &results) {
21
22
BenchmarkResult result;
22
23
uint64_t cycles_sum = 0 ;
23
24
double standard_deviation_sum = 0 ;
@@ -51,16 +52,16 @@ void Benchmark::run_benchmarks() {
51
52
uint64_t id = gpu::get_thread_id ();
52
53
gpu::sync_threads ();
53
54
54
- for (Benchmark *benchmark : benchmarks)
55
- results[id] = benchmark ->run ();
55
+ for (Benchmark *b : benchmarks)
56
+ results[id] = b ->run ();
56
57
gpu::sync_threads ();
57
58
if (id == 0 ) {
58
- for (Benchmark *benchmark : benchmarks) {
59
+ for (Benchmark const *b : benchmarks) {
59
60
BenchmarkResult all_results = reduce_results (results);
60
61
constexpr auto GREEN = " \033 [32m" ;
61
62
constexpr auto RESET = " \033 [0m" ;
62
- log << GREEN << " [ RUN ] " << RESET << benchmark ->get_name () << ' \n ' ;
63
- log << GREEN << " [ OK ] " << RESET << benchmark ->get_name () << " : "
63
+ log << GREEN << " [ RUN ] " << RESET << b ->get_name () << ' \n ' ;
64
+ log << GREEN << " [ OK ] " << RESET << b ->get_name () << " : "
64
65
<< all_results.cycles << " cycles, " << all_results.min << " min, "
65
66
<< all_results.max << " max, " << all_results.total_iterations
66
67
<< " iterations, " << all_results.total_time << " ns, "
@@ -82,7 +83,6 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
82
83
uint32_t samples = 0 ;
83
84
uint64_t total_time = 0 ;
84
85
uint64_t best_guess = 0 ;
85
- uint64_t total_cycles = 0 ;
86
86
uint64_t cycles_squared = 0 ;
87
87
uint64_t min = UINT64_MAX;
88
88
uint64_t max = 0 ;
@@ -92,23 +92,22 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
92
92
for (int i = 0 ; i < overhead_iterations; i++)
93
93
overhead = cpp::min (overhead, LIBC_NAMESPACE::overhead ());
94
94
95
- for (uint64_t time_budget = options.max_duration ; time_budget >= 0 ;) {
95
+ for (int64_t time_budget = options.max_duration ; time_budget >= 0 ;) {
96
96
uint64_t sample_cycles = 0 ;
97
97
const clock_t start = static_cast <double >(clock ());
98
98
for (uint32_t i = 0 ; i < iterations; i++) {
99
99
auto wrapper_intermediate = wrapper_func ();
100
- uint64_t result = wrapper_intermediate - overhead;
101
- max = cpp::max (max, result );
102
- min = cpp::min (min, result );
103
- sample_cycles += result ;
100
+ uint64_t current_result = wrapper_intermediate - overhead;
101
+ max = cpp::max (max, current_result );
102
+ min = cpp::min (min, current_result );
103
+ sample_cycles += current_result ;
104
104
}
105
105
const clock_t end = clock ();
106
106
const clock_t duration_ns =
107
107
((end - start) * 1000 * 1000 * 1000 ) / CLOCKS_PER_SEC;
108
108
total_time += duration_ns;
109
109
time_budget -= duration_ns;
110
110
samples++;
111
- total_cycles += sample_cycles;
112
111
cycles_squared += sample_cycles * sample_cycles;
113
112
114
113
total_iterations += iterations;
0 commit comments