-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcache-memory-bound.cpp
50 lines (39 loc) · 976 Bytes
/
cache-memory-bound.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <vector>
#include <chrono>
#include <memory>
#include <random>
#include <algorithm>
#ifndef REPETITIONS
#define REPETITIONS 10
#endif
#ifndef SIZE
#define SIZE 32 * 1024 * 1024
#endif
using Type = int;
void test_memory(std::vector<Type>& memory, int increment)
{
size_t size = memory.size();
using Clock = std::chrono::steady_clock;
auto start = Clock::now();
for (int i = 0; i < REPETITIONS; i++)
{
for (size_t j = 0; j < size; j += increment)
{
memory[j] *= 5;
}
}
std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start).count() << std::endl;
}
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cout << "Usage: cache-memory-bound <increment>" << std::endl;
return 1;
}
std::vector<Type> data(SIZE, 1);
int increment = std::stoi(argv[1]);
test_memory(data, increment);
return 0;
}