-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_02.cc
32 lines (29 loc) · 914 Bytes
/
example_02.cc
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
32
#include <random>
#include <vector>
#include <string>
#include <memstats.hh>
volatile void * do_not_optimize;
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
for (int rep = 1; rep != 4; ++rep) {
// only instrument a part of the code
memstats_enable_thread_instrumentation();
std::normal_distribution<> distrib(rep*100, 50);
for (int i = 0; i != 10000; ++i) {
std::vector<double> v(std::abs(distrib(gen)));
do_not_optimize = v.data();
}
memstats_disable_thread_instrumentation();
memstats_report( ("report " + std::to_string(rep)).c_str() );
}
{
// this part is not instrumented
std::normal_distribution<> distrib(200, 65);
for (int i = 0; i != 10000; ++i) {
std::vector<double> v(std::abs(distrib(gen)));
do_not_optimize = v.data();
}
}
}