-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_stress.cpp
79 lines (63 loc) · 1.8 KB
/
driver_stress.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
74
75
76
77
78
79
#include "unif01.h"
#include "bbattery.h"
#include "swrite.h"
#include "workload.hpp"
#include <iostream>
#include <random>
#include <chrono>
double score(double n, double g, double t)
{
double s=1.0;
double r=g / t;
if(r>1.0){
s *= exp(-r);
}
return log(n)/log(2.0) * s;
}
int main (int argc, char *argv[])
{
auto begin = std::chrono::system_clock::now();
std::mt19937 rng(time(0));
double t=2+rng()%28;
if(argc > 1){
t=strtod(argv[1], 0);
}
// Turn off all printing to stdout from TestU01
// You may want to try flipping this to 1 to see what it is actually doing.
swrite_Basic=0;
unif01_Gen *gen=workload_Create();
std::string name=workload_Name(gen);
double n;
// TODO : Choose the n that you think is achievable in timeBudget seconds
if(t>80){
n = t*1000000*20;
}
else if(t<23){
n = t*1000000*11; // This is just a throwaway example of how to choose
}
else if(t>40){
n = t*1000000*18;
}
else if(t>31){
n = t*1000000*14;
}
else{
n = t*1000000*10.5;
}
// Make sure this happens _before_ starting the battery, so that the
// client knows what you are trying.
fprintf(stdout, "%s, -1, TimeBudget, 0, %g\n", name.c_str(), t);
fprintf(stdout, "%s, -1, ChosenN, 0, %g\n", name.c_str(), n);
fflush(stdout);
// The slow part
auto results=bbattery_Rabbit(gen, n);
for(auto & r : results){
fprintf(stdout, "%s, %d, %s, %d, %.16g\n", name.c_str(), r.TestIndex, r.TestName.c_str(), r.SubIndex, r.pVal);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> span=end-begin;
double g=span.count();
fprintf(stdout, "%s, -1, TimeUsed, 0, %.16g\n", name.c_str(), g);
fprintf(stdout, "%s, -1, Score, 0, %.16g\n", name.c_str(), score(n, g, t));
return 0;
}