-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeneric_speedtest.cpp
73 lines (59 loc) · 1.51 KB
/
generic_speedtest.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "SACache.h"
#include "GenericCache.h"
#include "CacheMemory.h"
#include "time.h"
#include "RP_BIP.h"
#include "RP_RANDOM.h"
#include "RP_LRU.h"
#include "RP_PLRU.h"
#include "RP_QLRU.h"
#include "assert.h"
#define NUM_POLICIES 5
#define MAX_ITERATIONS 8
RPolicy* getPolicyObject(CacheConfig config, int policy_num);
int main()
{
CacheConfig config = {4, 3, 4, 6};
unsigned P = 1;
RMapper R(config, P, 0);
for (int i = 0; i < NUM_POLICIES; i++)
{
RPolicy* policy = getPolicyObject(config, i);
uint64_t total_time = 0;
for (int j = 0; j < MAX_ITERATIONS; j++)
{
auto* cache = new GenericCache(config, *policy, R, P);
size_t t = clock();
for (int i = 0; i < 1024 * 1024 * 16; i++)
{
uint64_t addr = 64 * (rand() % 2048);
cache->access({ addr, 0, false, false });
}
t = clock() - t;
total_time += t;
delete cache;
}
printf("Policy: %s, Average time (16M accesses): %f\n", policy->getPolicyName().c_str(), (double) total_time / MAX_ITERATIONS);
delete policy;
}
return 0;
}
RPolicy* getPolicyObject(CacheConfig config, int policy_num)
{
switch (policy_num)
{
case 0:
return new RP_LRU(config);
case 1:
return new RP_PLRU(config);
case 2:
return new RP_BIP(config);
case 3:
return new RP_RANDOM(config);
case 4:
return new RP_QLRU(config, { H00, M0, R0, U0, false });
default:
assert(false);
return NULL;
}
}