forked from fionser/PrivateDecisionTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_XCMP.cpp
71 lines (61 loc) · 1.96 KB
/
bench_XCMP.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
#include "GreaterThan.hpp"
#include "util/Timer.hpp"
#include "HElib/FHE.h"
#include <cmath>
std::pair<double, double> mean_std(std::vector<double> const& vals)
{
size_t sze = vals.size();
if (sze <= 1)
return {0., 0.};
double mean = 0.;
for (double v : vals) mean += v;
double std = 0.;
mean /= sze;
for (double v : vals)
std += (v - mean) * (v - mean);
std = std::sqrt(std / (sze - 1));
return {mean, std};
}
int main(int argc, char *argv[]) {
ArgMapping amap;
long m = 8192;
long p = 113; // small domain
long L = 4;
amap.arg("m", m, "m");
amap.arg("p", p, "p");
amap.arg("L", L, "L");
amap.parse(argc, argv);
FHEcontext context(m, p, 1);
buildModChain(context, L);
std::cout << "kappa " << context.securityLevel() << std::endl;
FHESecKey sk(context);
sk.GenSecKey(64);
setup_auxiliary_for_greater_than(&sk);
FHEPubKey pk = sk;
std::vector<double> times[3];
for (long _it = 0; _it < 100; _it++) {
Timer timer(nullptr);
auto start_ = Timer::Clock::now();
Ctxt enc_a = encrypt_in_degree(127, pk);
Ctxt enc_b = encrypt_in_degree(48, pk);
auto end_ = Timer::Clock::now();
times[0].push_back(timer.as_millsecond(end_ - start_));
auto gt_args = create_greater_than_args(0, 1, context);
start_ = Timer::Clock::now();
auto ans = greater_than(enc_a, enc_b, context);
end_ = Timer::Clock::now();
times[1].push_back(timer.as_millsecond(end_ - start_));
NTL::ZZX ply;
start_ = Timer::Clock::now();
sk.Decrypt(ply, ans);
end_ = Timer::Clock::now();
times[2].push_back(timer.as_millsecond(end_ - start_));
}
auto ms = mean_std(times[0]);
std::cout << ms.first << " " << ms.second << "\n";
ms = mean_std(times[1]);
std::cout << ms.first << " " << ms.second << "\n";
ms = mean_std(times[2]);
std::cout << ms.first << " " << ms.second << "\n";
return 0;
}