-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathspeedtesting.cpp
More file actions
129 lines (122 loc) · 4.22 KB
/
speedtesting.cpp
File metadata and controls
129 lines (122 loc) · 4.22 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* You may consider this code to be in the public domain.
*
* Daniel Lemire, September 2010.
*
*/
/**
* Compile as g++ -O3 -o speedtesting speedtesting.cpp
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <typeinfo>
#include "ztimer.h"
#include "hashfunctions.h"
#include "ZRandom.h"
using namespace std;
template <class T, class INTEGER>
double testSpeed(const T & hasher, const vector<INTEGER> & data, uint64 & answer, const uint mN) {
ZTimer t;
double timeelapsed;
t.reset();
answer += hasher.hash(&data[0],&data[0]+mN);
timeelapsed = t.split()/(1000.0);
return timeelapsed;
}
template <class T, class INTEGER>
double testSpeedManyTimes(const T & hasher, const vector<INTEGER> & data, uint64 & answer, const uint mN,const uint times) {
ZTimer t;
double timeelapsed;
t.reset();
for(uint k = 0; k<times;++k)
answer += hasher.hash(&data[0],&data[0]+mN);
timeelapsed = t.split()/(1000.0);
return timeelapsed;
}
int main(int params, char ** args) {
uint N;
if (params >= 2)
N = atoi(args[1]);
else {
N = 1024*1024;
}
cout<<"#sizeof(uint64)="<<sizeof(uint64)<<endl;
assert(sizeof(uint64)==8);
cout<<"# Initializing data..."<<endl;
vector<uint32>data(N);
vector<uint64>randombuffer64(N+1);
//MTRand mt;
ZRandom zr;
for(uint k = 0;k<N;++k) {
data[k] = zr.getValue();//mt.randInt();
}
data.push_back(1);// so that it never ends with a zero
if( (data.size() & 1) != 0) data.push_back(0);// make sure it is even
cout<<"# done generating data"<<endl;
cout<<"# "<<data.size()*sizeof(uint)/(1024.0*1024.0)<<" MB"<<endl;
ZTimer t;
for(uint k = 0;k<=N+2;++k) {
randombuffer64[k] =zr.getValue() & (static_cast<uint64>(zr.getValue())<<32 ) ;
}
double timeelapsed = t.split()/(1000.0);
cout<<"# random generated in "<<timeelapsed<< " or "<<N*sizeof(uint64)/(1024.0*1024*1024*timeelapsed)<<" GB/s"<<endl;
cout<<"# "<<data.size()*sizeof(uint64)/(1024.0*1024.0)<<" MB"<<endl;
const uint times = 20;
uint64 answer = 0;
Silly silly;
Thorup thorup(randombuffer64);
StrongMultilinear sm(randombuffer64);
PyramidalMultilinear pm(randombuffer64);
XAMA xama(randombuffer64);
#if defined (__PCLMUL__) && (__SSE2__)
CLStrongMultilinear clsm(randombuffer64);
#endif
NoMultiplication testing(randombuffer64);
StrongMultilinearTwoByTwo sm2by2(randombuffer64);
const uint shorttimes =2000000;
cout<<"# Starting tests... repeating each run "<<shorttimes<<" times"<<endl;
cout<<"# N silly thorup09(not-strongly-universal) xama strong-multilinear strong-multilinear-2by2 pyramidalmultilinear clmulti*"<<endl;
for(uint mN = 1024; mN<=2048; mN*=2) {
vector<double> counter(7,0);
counter[0]+=testSpeedManyTimes(silly,data,answer,mN,shorttimes);
counter[1]+=testSpeedManyTimes(thorup,data,answer,mN,shorttimes);
counter[2]+=testSpeedManyTimes(xama,data,answer,mN,shorttimes);
counter[3]+=testSpeedManyTimes(sm,data,answer,mN,shorttimes);
counter[4]+=testSpeedManyTimes(sm2by2,data,answer,mN,shorttimes);
counter[5]+=testSpeedManyTimes(pm,data,answer,mN,shorttimes);
#if defined (__PCLMUL__) && (__SSE2__)
counter[6]+=testSpeedManyTimes(clsm,data,answer,mN,shorttimes);
#endif
cout<<mN<<" ";
for(uint k = 0; k<counter.size();++k)
cout<<counter[k]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"# Starting tests... repeating each run "<<times<<" times"<<endl;
cout<<"# N silly thorup09(not-strongly-universal) xama strong-multilinear strong-multilinear-2by2 pyramidalmultilinear clmulti*"<<endl;
for(uint mN = 1048576; mN<=data.size(); mN*=2) {
vector<double> counter(7,0);
for(uint k = 0;k<times;++k) {
counter[0]+=testSpeed(silly,data,answer,mN);
counter[1]+=testSpeed(thorup,data,answer,mN);
counter[2]+=testSpeedManyTimes(xama,data,answer,mN,shorttimes);
counter[3]+=testSpeed(sm,data,answer,mN);
counter[4]+=testSpeed(sm2by2,data,answer,mN);
counter[5]+=testSpeed(pm,data,answer,mN);
#if defined (__PCLMUL__) && (__SSE2__)
counter[6]+=testSpeedManyTimes(clsm,data,answer,mN,shorttimes);
#endif
}
cout<<mN<<" ";
for(uint k = 0; k<counter.size();++k)
cout<<counter[k]<<" ";
cout<<endl;
}
cout<<endl;
return answer;
}