Skip to content

Commit

Permalink
adding branch misses
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Jan 31, 2024
1 parent 2f86508 commit d62e8a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 7 additions & 1 deletion benchmarks/apple_arm_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,13 @@ inline performance_counters get_counters() {
}
return 1;
}

/*printf("counters value:\n");
for (usize i = 0; i < ev_count; i++) {
const event_alias *alias = profile_events + i;
usize idx = counter_map[i];
u64 val = counters_1[idx] - counters_0[idx];
printf("%14s: %llu\n", alias->alias, val);
}*/
return performance_counters{
counters_0[counter_map[0]], counters_0[counter_map[2]],
counters_0[counter_map[3]],
Expand Down
8 changes: 8 additions & 0 deletions benchmarks/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ void pretty_print(double volume, size_t number_of_floats, std::string name, std:
double instructions_avg{0};
double branches_min{0};
double branches_avg{0};
double branch_misses_min{0};
double branch_misses_avg{0};
for(event_count e : events) {
double ns = e.elapsed_ns();
average_ns += ns;
Expand All @@ -249,6 +251,10 @@ void pretty_print(double volume, size_t number_of_floats, std::string name, std:
double branches = e.branches();
branches_avg += branches;
branches_min = branches_min < branches ? branches_min : branches;

double branch_misses = e.missed_branches();
branch_misses_avg += branch_misses;
branch_misses_min = branch_misses_min < branch_misses ? branch_misses_min : branch_misses;
}
cycles_avg /= events.size();
instructions_avg /= events.size();
Expand All @@ -273,6 +279,8 @@ void pretty_print(double volume, size_t number_of_floats, std::string name, std:
instructions_min /cycles_min);
printf(" %8.2f b/f ",
branches_avg /number_of_floats);
printf(" %8.2f bm/f ",
branch_misses_avg /number_of_floats);
printf(" %8.2f GHz ",
cycles_min / min_ns);
}
Expand Down
10 changes: 0 additions & 10 deletions benchmarks/event_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,18 @@ struct event_count {

// The types of counters (so we can read the getter more easily)
enum event_counter_types {
<<<<<<< HEAD
CPU_CYCLES,
INSTRUCTIONS,
BRANCH_MISSES
=======
CPU_CYCLES = 0,
INSTRUCTIONS = 1,
BRANCHES = 2,
MISSED_BRANCHES = 3
>>>>>>> 2d0d081779f796041fbaf8791e99509f7f226dac
};

double elapsed_sec() const { return std::chrono::duration<double>(elapsed).count(); }
double elapsed_ns() const { return std::chrono::duration<double, std::nano>(elapsed).count(); }
double cycles() const { return static_cast<double>(event_counts[CPU_CYCLES]); }
double instructions() const { return static_cast<double>(event_counts[INSTRUCTIONS]); }
<<<<<<< HEAD
double branch_misses() const { return static_cast<double>(event_counts[BRANCH_MISSES]); }
=======
double branches() const { return static_cast<double>(event_counts[BRANCHES]); }
double missed_branches() const { return static_cast<double>(event_counts[MISSED_BRANCHES]); }
>>>>>>> 2d0d081779f796041fbaf8791e99509f7f226dac

event_count& operator=(const event_count& other) {
this->elapsed = other.elapsed;
Expand Down

0 comments on commit d62e8a8

Please sign in to comment.