-
Notifications
You must be signed in to change notification settings - Fork 3
/
perftest.cpp
110 lines (90 loc) · 3.26 KB
/
perftest.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "termpose.cpp"
using namespace termpose;
#include <string>
#include <unordered_map>
#include <cassert>
#include <sstream>
#include <chrono>
using namespace std;
using namespace termpose::parsingDSL;
Term makeTestTerm(unsigned nInts){
vector<Term> out;
out.reserve(nInts + 1);
out.emplace_back("inside");
string ss;
for(uint i=0; i<nInts; ++i){
string key("adb");
key += to_string(i);
out.emplace_back(terms(key, "hoble"));
}
return out;
}
vector<unsigned> fairlyRandomNumberSequence;
unsigned curi=0;
unsigned nextRand(){
unsigned ret = fairlyRandomNumberSequence[curi];
++curi;
if(curi == fairlyRandomNumberSequence.size()){ curi = 0; }
return ret;
}
unsigned acc=0;
void test(unsigned setSize, unsigned probes, unsigned repetitions){
cout<< "setSize:"<<setSize<<" probes:"<<probes<<" repetitions:"<<repetitions<<endl;
Term testTerm = makeTestTerm(setSize);
auto start_time = std::chrono::high_resolution_clock::now();
for(uint i=0; i<repetitions; ++i){
for(uint j=0; j<probes; ++j){
string key("adb");
key += to_string(nextRand()%setSize);
Term& v = testTerm.findTerm(key);
if(v.isList()){ acc += 1; }
}
}
auto current_time = std::chrono::high_resolution_clock::now();
cout<< " linear lookup took "<< std::chrono::duration_cast<std::chrono::milliseconds>(current_time - start_time).count() << " milliseconds" << std::endl;
vector<pair<string, string>> pairs = sliceOffTag("inside", sequenceTrans(pairTrans(stringTrans(), stringTrans())))->check(testTerm);
auto linear_pure_start_time = std::chrono::high_resolution_clock::now();
for(uint i=0; i<repetitions; ++i){
for(uint j=0; j<probes; ++j){
string key("adb");
key += to_string(nextRand()%setSize);
for(uint k=0; k<pairs.size(); ++k){
if(pairs[k].first == key){
acc += 1;
break;
}
}
}
}
auto linear_pure_current_time = std::chrono::high_resolution_clock::now();
cout<< " linear pure lookup took "<< std::chrono::duration_cast<std::chrono::milliseconds>(linear_pure_current_time - linear_pure_start_time).count() << " milliseconds" << std::endl;
unordered_map<string, string> mrep = sliceOffTag("inside", mapTrans(stringTrans(), stringTrans()))->check(testTerm);
auto map_start_time = std::chrono::high_resolution_clock::now();
for(uint i=0; i<repetitions; ++i){
for(uint j=0; j<probes; ++j){
string key("adb");
key += to_string(nextRand()%setSize);
string v = mrep.at(key);
if(v.size() >= 1){ acc += 1; }
}
}
auto map_current_time = std::chrono::high_resolution_clock::now();
cout<< " constant lookup took "<< std::chrono::duration_cast<std::chrono::milliseconds>(map_current_time - map_start_time).count() << " milliseconds" << std::endl;
}
int main(){
fairlyRandomNumberSequence.push_back(9239);
fairlyRandomNumberSequence.push_back(33841);
fairlyRandomNumberSequence.push_back(79);
for(uint i=0; i<1345; ++i){
unsigned lll = fairlyRandomNumberSequence[fairlyRandomNumberSequence.size()-3];
unsigned ll = fairlyRandomNumberSequence[fairlyRandomNumberSequence.size()-2];
unsigned l = fairlyRandomNumberSequence[fairlyRandomNumberSequence.size()-1];
fairlyRandomNumberSequence.push_back(lll ^ (ll*l + lll));
}
test(5, 100, 600);
test(10, 100, 600);
test(20, 100, 600);
test(40, 100, 600);
test(80, 100, 600);
return 0;
}