-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.cpp
More file actions
31 lines (23 loc) · 706 Bytes
/
Copy pathexample.cpp
File metadata and controls
31 lines (23 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "PapiInstance.h"
#include <cmath>
#include <iostream>
int main(int argc, char **argv) {
const int loopLimit(10000);
Papi papi;
auto instance = papi.create();
instance->addEvent(PAPI_TOT_INS);
instance->addEvent(PAPI_BR_MSP);
instance->start();
for (int i = 0; i < loopLimit; ++i) {
auto res = std::pow(std::atoi(argv[1]), 2);
if (int(res) % 10 == 0) {
std::cout << "branch taken" << std::endl;
}
}
instance->stop();
std::cout << "Total instructions: " << instance->getEventValue(PAPI_TOT_INS)
<< std::endl;
std::cout << "Branch instructins misspredicted: "
<< instance->getEventValue(PAPI_BR_MSP) << std::endl;
return 0;
}