Skip to content

Commit 8832c53

Browse files
committed
lint
1 parent 3f2cd66 commit 8832c53

File tree

4 files changed

+125
-127
lines changed

4 files changed

+125
-127
lines changed

benchmarks/apple_arm_events.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ inline performance_counters operator-(const performance_counters &a,
101101
a.instructions - b.instructions);
102102
}
103103

104-
105-
106104
typedef float f32;
107105
typedef double f64;
108106
typedef int8_t i8;
@@ -616,9 +614,7 @@ typedef struct {
616614

617615
#define lib_nelems(x) (sizeof(x) / sizeof((x)[0]))
618616
#define lib_symbol_def(name) \
619-
{ \
620-
#name, (void **)&name \
621-
}
617+
{ #name, (void **)&name }
622618

623619
static const lib_symbol lib_symbols_kperf[] = {
624620
lib_symbol_def(kpc_pmu_version),
@@ -933,7 +929,7 @@ typedef struct {
933929
static const event_alias profile_events[] = {
934930
{"cycles",
935931
{
936-
"FIXED_CYCLES", // Apple A7-A15//CORE_ACTIVE_CYCLE
932+
"FIXED_CYCLES", // Apple A7-A15//CORE_ACTIVE_CYCLE
937933
"CPU_CLK_UNHALTED.THREAD", // Intel Core 1th-10th
938934
"CPU_CLK_UNHALTED.CORE", // Intel Yonah, Merom
939935
}},
@@ -976,7 +972,6 @@ u64 counters_0[KPC_MAX_COUNTERS] = {0};
976972
u64 counters_1[KPC_MAX_COUNTERS] = {0};
977973
const usize ev_count = sizeof(profile_events) / sizeof(profile_events[0]);
978974

979-
980975
bool setup_performance_counters() {
981976
static bool init = false;
982977
static bool worked = false;
@@ -995,7 +990,7 @@ bool setup_performance_counters() {
995990
// check permission
996991
int force_ctrs = 0;
997992
if (kpc_force_all_ctrs_get(&force_ctrs)) {
998-
//printf("Permission denied, xnu/kpc requires root privileges.\n");
993+
// printf("Permission denied, xnu/kpc requires root privileges.\n");
999994
return (worked = false);
1000995
}
1001996
int ret;
@@ -1101,17 +1096,16 @@ inline performance_counters get_counters() {
11011096
}
11021097
return 1;
11031098
}
1104-
/*printf("counters value:\n");
1105-
for (usize i = 0; i < ev_count; i++) {
1106-
const event_alias *alias = profile_events + i;
1107-
usize idx = counter_map[i];
1108-
u64 val = counters_1[idx] - counters_0[idx];
1109-
printf("%14s: %llu\n", alias->alias, val);
1110-
}*/
1099+
/*printf("counters value:\n");
1100+
for (usize i = 0; i < ev_count; i++) {
1101+
const event_alias *alias = profile_events + i;
1102+
usize idx = counter_map[i];
1103+
u64 val = counters_1[idx] - counters_0[idx];
1104+
printf("%14s: %llu\n", alias->alias, val);
1105+
}*/
11111106
return performance_counters{
11121107
counters_0[counter_map[0]], counters_0[counter_map[2]],
1113-
counters_0[counter_map[3]],
1114-
counters_0[counter_map[1]]};
1108+
counters_0[counter_map[3]], counters_0[counter_map[1]]};
11151109
}
11161110

11171111
#endif

benchmarks/benchmark.cpp

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(__linux__) || (__APPLE__ && __aarch64__)
1+
#if defined(__linux__) || (__APPLE__ && __aarch64__)
22
#define USING_COUNTERS
33
#include "event_counter.h"
44
#endif
@@ -22,7 +22,6 @@
2222
#include <vector>
2323
#include <locale.h>
2424

25-
2625
template <typename CharT>
2726
double findmax_fastfloat64(std::vector<std::basic_string<CharT>> &s) {
2827
double answer = 0;
@@ -55,8 +54,9 @@ event_collector collector{};
5554

5655
#ifdef USING_COUNTERS
5756
template <class T, class CharT>
58-
std::vector<event_count> time_it_ns(std::vector<std::basic_string<CharT>> &lines,
59-
T const &function, size_t repeat) {
57+
std::vector<event_count>
58+
time_it_ns(std::vector<std::basic_string<CharT>> &lines, T const &function,
59+
size_t repeat) {
6060
std::vector<event_count> aggregate;
6161
bool printed_bug = false;
6262
for (size_t i = 0; i < repeat; i++) {
@@ -71,7 +71,8 @@ std::vector<event_count> time_it_ns(std::vector<std::basic_string<CharT>> &lines
7171
return aggregate;
7272
}
7373

74-
void pretty_print(double volume, size_t number_of_floats, std::string name, std::vector<event_count> events) {
74+
void pretty_print(double volume, size_t number_of_floats, std::string name,
75+
std::vector<event_count> events) {
7576
double volumeMB = volume / (1024. * 1024.);
7677
double average_ns{0};
7778
double min_ns{DBL_MAX};
@@ -83,7 +84,7 @@ void pretty_print(double volume, size_t number_of_floats, std::string name, std:
8384
double branches_avg{0};
8485
double branch_misses_min{0};
8586
double branch_misses_avg{0};
86-
for(event_count e : events) {
87+
for (event_count e : events) {
8788
double ns = e.elapsed_ns();
8889
average_ns += ns;
8990
min_ns = min_ns < ns ? min_ns : ns;
@@ -94,51 +95,46 @@ void pretty_print(double volume, size_t number_of_floats, std::string name, std:
9495

9596
double instructions = e.instructions();
9697
instructions_avg += instructions;
97-
instructions_min = instructions_min < instructions ? instructions_min : instructions;
98+
instructions_min =
99+
instructions_min < instructions ? instructions_min : instructions;
98100

99101
double branches = e.branches();
100102
branches_avg += branches;
101103
branches_min = branches_min < branches ? branches_min : branches;
102104

103105
double branch_misses = e.missed_branches();
104106
branch_misses_avg += branch_misses;
105-
branch_misses_min = branch_misses_min < branch_misses ? branch_misses_min : branch_misses;
107+
branch_misses_min =
108+
branch_misses_min < branch_misses ? branch_misses_min : branch_misses;
106109
}
107110
cycles_avg /= events.size();
108111
instructions_avg /= events.size();
109112
average_ns /= events.size();
110113
branches_avg /= events.size();
111114
printf("%-40s: %8.2f MB/s (+/- %.1f %%) ", name.data(),
112-
volumeMB * 1000000000 / min_ns,
113-
(average_ns - min_ns) * 100.0 / average_ns);
114-
printf("%8.2f Mfloat/s ",
115-
number_of_floats * 1000 / min_ns);
116-
if(instructions_min > 0) {
117-
printf(" %8.2f i/B %8.2f i/f (+/- %.1f %%) ",
118-
instructions_min / volume,
119-
instructions_min / number_of_floats,
115+
volumeMB * 1000000000 / min_ns,
116+
(average_ns - min_ns) * 100.0 / average_ns);
117+
printf("%8.2f Mfloat/s ", number_of_floats * 1000 / min_ns);
118+
if (instructions_min > 0) {
119+
printf(" %8.2f i/B %8.2f i/f (+/- %.1f %%) ", instructions_min / volume,
120+
instructions_min / number_of_floats,
120121
(instructions_avg - instructions_min) * 100.0 / instructions_avg);
121122

122-
printf(" %8.2f c/B %8.2f c/f (+/- %.1f %%) ",
123-
cycles_min / volume,
124-
cycles_min / number_of_floats,
123+
printf(" %8.2f c/B %8.2f c/f (+/- %.1f %%) ", cycles_min / volume,
124+
cycles_min / number_of_floats,
125125
(cycles_avg - cycles_min) * 100.0 / cycles_avg);
126-
printf(" %8.2f i/c ",
127-
instructions_min /cycles_min);
128-
printf(" %8.2f b/f ",
129-
branches_avg /number_of_floats);
130-
printf(" %8.2f bm/f ",
131-
branch_misses_avg /number_of_floats);
132-
printf(" %8.2f GHz ",
133-
cycles_min / min_ns);
126+
printf(" %8.2f i/c ", instructions_min / cycles_min);
127+
printf(" %8.2f b/f ", branches_avg / number_of_floats);
128+
printf(" %8.2f bm/f ", branch_misses_avg / number_of_floats);
129+
printf(" %8.2f GHz ", cycles_min / min_ns);
134130
}
135131
printf("\n");
136-
137132
}
138133
#else
139134
template <class T, class CharT>
140-
std::pair<double, double> time_it_ns(std::vector<std::basic_string<CharT>> &lines,
141-
T const &function, size_t repeat) {
135+
std::pair<double, double>
136+
time_it_ns(std::vector<std::basic_string<CharT>> &lines, T const &function,
137+
size_t repeat) {
142138
std::chrono::high_resolution_clock::time_point t1, t2;
143139
double average = 0;
144140
double min_value = DBL_MAX;
@@ -160,21 +156,16 @@ std::pair<double, double> time_it_ns(std::vector<std::basic_string<CharT>> &line
160156
return std::make_pair(min_value, average);
161157
}
162158

163-
164-
165-
166-
void pretty_print(double volume, size_t number_of_floats, std::string name, std::pair<double,double> result) {
159+
void pretty_print(double volume, size_t number_of_floats, std::string name,
160+
std::pair<double, double> result) {
167161
double volumeMB = volume / (1024. * 1024.);
168162
printf("%-40s: %8.2f MB/s (+/- %.1f %%) ", name.data(),
169-
volumeMB * 1000000000 / result.first,
170-
(result.second - result.first) * 100.0 / result.second);
171-
printf("%8.2f Mfloat/s ",
172-
number_of_floats * 1000 / result.first);
173-
printf(" %8.2f ns/f \n",
174-
double(result.first) /number_of_floats );
163+
volumeMB * 1000000000 / result.first,
164+
(result.second - result.first) * 100.0 / result.second);
165+
printf("%8.2f Mfloat/s ", number_of_floats * 1000 / result.first);
166+
printf(" %8.2f ns/f \n", double(result.first) / number_of_floats);
175167
}
176-
#endif
177-
168+
#endif
178169

179170
// this is okay, all chars are ASCII
180171
inline std::u16string widen(std::string line) {
@@ -195,21 +186,23 @@ std::vector<std::u16string> widen(const std::vector<std::string> &lines) {
195186
return u16lines;
196187
}
197188

198-
199189
void process(std::vector<std::string> &lines, size_t volume) {
200190
size_t repeat = 100;
201191
double volumeMB = volume / (1024. * 1024.);
202192
std::cout << "ASCII volume = " << volumeMB << " MB " << std::endl;
203-
pretty_print(volume, lines.size(), "fastfloat (64)", time_it_ns(lines, findmax_fastfloat64<char>, repeat));
204-
pretty_print(volume, lines.size(), "fastfloat (32)", time_it_ns(lines, findmax_fastfloat32<char>, repeat));
193+
pretty_print(volume, lines.size(), "fastfloat (64)",
194+
time_it_ns(lines, findmax_fastfloat64<char>, repeat));
195+
pretty_print(volume, lines.size(), "fastfloat (32)",
196+
time_it_ns(lines, findmax_fastfloat32<char>, repeat));
205197

206198
std::vector<std::u16string> lines16 = widen(lines);
207199
volume = 2 * volume;
208200
volumeMB = volume / (1024. * 1024.);
209201
std::cout << "UTF-16 volume = " << volumeMB << " MB " << std::endl;
210-
pretty_print(volume, lines.size(), "fastfloat (64)", time_it_ns(lines16, findmax_fastfloat64<char16_t>, repeat));
211-
pretty_print(volume, lines.size(), "fastfloat (32)", time_it_ns(lines16, findmax_fastfloat32<char16_t>, repeat));
212-
202+
pretty_print(volume, lines.size(), "fastfloat (64)",
203+
time_it_ns(lines16, findmax_fastfloat64<char16_t>, repeat));
204+
pretty_print(volume, lines.size(), "fastfloat (32)",
205+
time_it_ns(lines16, findmax_fastfloat32<char16_t>, repeat));
213206
}
214207

215208
void fileload(std::string filename) {
@@ -233,13 +226,14 @@ void fileload(std::string filename) {
233226
process(lines, volume);
234227
}
235228

236-
237229
int main(int argc, char **argv) {
238-
if(collector.has_events()) {
230+
if (collector.has_events()) {
239231
std::cout << "# Using hardware counters" << std::endl;
240232
} else {
241-
#if defined(__linux__) || (__APPLE__ && __aarch64__)
242-
std::cout << "# Hardware counters not available, try to run in privileged mode (e.g., sudo)." << std::endl;
233+
#if defined(__linux__) || (__APPLE__ && __aarch64__)
234+
std::cout << "# Hardware counters not available, try to run in privileged "
235+
"mode (e.g., sudo)."
236+
<< std::endl;
243237
#endif
244238
}
245239
fileload(std::string(BENCHMARK_DATA_DIR) + "/canada.txt");

0 commit comments

Comments
 (0)