-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbenchmark.cpp
80 lines (70 loc) · 1.94 KB
/
benchmark.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
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include "dtw.h"
vector<double> getrandomwalk(uint size) {
vector<double> data(size);
data[0] = 0.0;
for (uint k = 1; k < size; ++k)
data[k] = (1.0 * rand() / (RAND_MAX)) - 0.5 + data[k - 1];
return data;
}
vector<double> getcin() {
float val;
cin >> val;
vector<double> v;
while (cin) {
v.push_back(val);
cin >> val;
}
cout << "# Read " << v.size() << " data points. " << endl;
return v;
}
template <class NN>
vector<uint> RunMe(vector<vector<double> > &collection,
vector<vector<double> > &testcollection) {
vector<uint> bestmatches;
clock_t start, finish;
start = clock();
for (uint k = 0; k < testcollection.size(); ++k) {
NN n(testcollection[k],
testcollection[k].size() / 10); // window set at 10%, arbitrarily
double current = n.getLowestCost();
uint bestmatch = 0;
for (uint z = 0; z < collection.size(); ++z) {
double newc = n.test(collection[z]);
if (newc < current) { // best candidate so far
current = newc;
bestmatch = z;
}
}
bestmatches.push_back(bestmatch);
}
finish = clock();
cout << "CPU time = " << static_cast<double>(finish - start) / CLOCKS_PER_SEC
<< endl;
return bestmatches;
}
void runbenchmark() {
uint N = 128;
vector<vector<double> > collection;
vector<vector<double> > testcollection;
for (uint i = 0; i < 512; ++i) {
collection.push_back(getrandomwalk(N));
testcollection.push_back(getrandomwalk(N));
}
cout << "LB Keogh" << endl;
RunMe<LB_Keogh>(collection, testcollection);
cout << "LB Keogh (early)" << endl;
RunMe<LB_KeoghEarly>(collection, testcollection);
cout << "LB Improved" << endl;
RunMe<LB_Improved>(collection, testcollection);
cout << "LB Improved (early)" << endl;
RunMe<LB_ImprovedEarly>(collection, testcollection);
}
int main() {
runbenchmark();
return 0;
}