-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbench.cpp
97 lines (85 loc) · 3.79 KB
/
bench.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
#include "dpf.h"
#include "hashdatastore.h"
#include <chrono>
#include <iostream>
void benchEvalFull(size_t N, size_t iter) {
std::chrono::duration<double> buildT, evalT, answerT;
buildT = evalT = answerT = std::chrono::duration<double>::zero();
std::cout << "EvalFull, " << iter << " iterations" << std::endl;
auto time1 = std::chrono::high_resolution_clock::now();
auto keys = DPF::Gen(0, N);
auto a = keys.first;
auto time2 = std::chrono::high_resolution_clock::now();
for(size_t i = 0; i < iter; i++) {
std::vector<uint8_t> aaaa = DPF::EvalFull(a, N);
}
auto time3 = std::chrono::high_resolution_clock::now();
buildT += time2 - time1;
evalT += time3 - time2;
std::cout << buildT.count() << "sec" << std::endl;
std::cout << evalT.count() << "sec" << std::endl;
}
void benchEvalFull8(size_t N, size_t iter) {
std::chrono::duration<double> buildT, evalT, answerT;
buildT = evalT = answerT = std::chrono::duration<double>::zero();
std::cout << "EvalFull8, " << iter << " iterations" << std::endl;
auto time1 = std::chrono::high_resolution_clock::now();
auto keys = DPF::Gen(0, N);
auto a = keys.first;
auto time2 = std::chrono::high_resolution_clock::now();
for(size_t i = 0; i < iter; i++) {
std::vector<uint8_t> aaaa = DPF::EvalFull8(a, N);
}
auto time3 = std::chrono::high_resolution_clock::now();
buildT += time2 - time1;
evalT += time3 - time2;
std::cout << buildT.count() << "sec" << std::endl;
std::cout << evalT.count() << "sec" << std::endl;
}
void benchAnswerPIR(size_t N, size_t iter) {
std::array<std::chrono::duration<double>,6> answerT = {std::chrono::duration<double>::zero(), };
std::cout << "AnswerPIR, " << iter << " iterations" << std::endl;
auto keys = DPF::Gen(0, N);
auto a = keys.first;
hashdatastore store;
store.reserve(1ULL << N);
for (size_t i = 0; i < (1ULL << N); i++) {
store.push_back(_mm256_set_epi64x(i, i, i, i));
}
std::vector<uint8_t> aaaa = DPF::EvalFull8(a, N);
for(size_t i = 0; i < iter; i++) {
auto time0 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer0 = store.answer_pir_idea_speed_comparison(aaaa);
auto time1 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer1 = store.answer_pir1(aaaa);
auto time2 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer2 = store.answer_pir2(aaaa);
auto time3 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer3 = store.answer_pir3(aaaa);
auto time4 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer4 = store.answer_pir4(aaaa);
auto time5 = std::chrono::high_resolution_clock::now();
hashdatastore::hash_type answer5 = store.answer_pir5(aaaa);
auto time6 = std::chrono::high_resolution_clock::now();
answerT[0] += time1-time0;
answerT[1] += time2-time1;
answerT[2] += time3-time2;
answerT[3] += time4-time3;
answerT[4] += time5-time4;
answerT[5] += time6-time5;
}
std::cout << "AnswerPIR ideal " << answerT[0].count() << "sec" << std::endl;
std::cout << "AnswerPIR1 " << answerT[1].count() << "sec" << std::endl;
std::cout << "AnswerPIR2 " << answerT[2].count() << "sec" << std::endl;
std::cout << "AnswerPIR3 " << answerT[3].count() << "sec" << std::endl;
std::cout << "AnswerPIR4 " << answerT[4].count() << "sec" << std::endl;
std::cout << "AnswerPIR5 " << answerT[5].count() << "sec" << std::endl;
}
int main(int argc, char** argv) {
size_t N = 27;
size_t iter = 100;
benchEvalFull(N, iter);
benchEvalFull8(N, iter);
benchAnswerPIR(25,100);
return 0;
}