Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
multiexp_profile.cpp
Go to the documentation of this file.
1#include <cstdio>
2#include <vector>
3
8
9using namespace libff;
10
11template <typename GroupT>
12using run_result_t = std::pair<long long, std::vector<GroupT> >;
13
14template <typename T>
15using test_instances_t = std::vector<std::vector<T> >;
16
17template<typename GroupT>
19{
20 // generating a random group element is expensive,
21 // so for now we only generate a single one and repeat it
23
24 for (size_t i = 0; i < count; i++) {
25 GroupT x = GroupT::random_element();
26 x.to_special(); // djb requires input to be in special form
27 for (size_t j = 0; j < size; j++) {
28 result[i].push_back(x);
29 // result[i].push_back(GroupT::random_element());
30 }
31 }
32
33 return result;
34}
35
36template<typename FieldT>
38{
39 // we use SHA512_rng because it is much faster than
40 // FieldT::random_element()
42
43 for (size_t i = 0; i < count; i++) {
44 for (size_t j = 0; j < size; j++) {
45 result[i].push_back(SHA512_rng<FieldT>(i * size + j));
46 }
47 }
48
49 return result;
50}
51
52template<typename GroupT, typename FieldT, multi_exp_method Method>
54 test_instances_t<GroupT> group_elements,
56{
57 long long start_time = get_nsec_time();
58
59 std::vector<GroupT> answers;
60 for (size_t i = 0; i < group_elements.size(); i++) {
61 answers.push_back(multi_exp<GroupT, FieldT, Method>(
62 group_elements[i].cbegin(), group_elements[i].cend(),
63 scalars[i].cbegin(), scalars[i].cend(),
64 1));
65 }
66
67 long long time_delta = get_nsec_time() - start_time;
68
69 return run_result_t<GroupT>(time_delta, answers);
70}
71
72template<typename GroupT, typename FieldT>
74 size_t expn_start,
75 size_t expn_end_fast,
76 size_t expn_end_naive,
77 bool compare_answers)
78{
79 for (size_t expn = expn_start; expn <= expn_end_fast; expn++) {
80 printf("%ld", expn); fflush(stdout);
81
82 test_instances_t<GroupT> group_elements =
85 generate_scalars<FieldT>(10, 1 << expn);
86
87 run_result_t<GroupT> result_bos_coster =
89 group_elements, scalars);
90 printf("\t%lld", result_bos_coster.first); fflush(stdout);
91
92 run_result_t<GroupT> result_djb =
94 group_elements, scalars);
95 printf("\t%lld", result_djb.first); fflush(stdout);
96
97 if (compare_answers && (result_bos_coster.second != result_djb.second)) {
98 fprintf(stderr, "Answers NOT MATCHING (bos coster != djb)\n");
99 }
100
101 if (expn <= expn_end_naive) {
102 run_result_t<GroupT> result_naive =
104 group_elements, scalars);
105 printf("\t%lld", result_naive.first); fflush(stdout);
106
107 if (compare_answers && (result_bos_coster.second != result_naive.second)) {
108 fprintf(stderr, "Answers NOT MATCHING (bos coster != naive)\n");
109 }
110 }
111
112 printf("\n");
113 }
114}
115
116int main(void)
117{
119
120 printf("Profiling BN128_G1\n");
123
124 printf("Profiling BN128_G2\n");
126
127 return 0;
128}
static void init_public_params()
Definition bn128_pp.cpp:13
int * count
std::pair< long long, std::vector< GroupT > > run_result_t
std::vector< std::vector< T > > test_instances_t
int main(void)
run_result_t< GroupT > profile_multiexp(test_instances_t< GroupT > group_elements, test_instances_t< FieldT > scalars)
void print_performance_csv(size_t expn_start, size_t expn_end_fast, size_t expn_end_naive, bool compare_answers)
test_instances_t< FieldT > generate_scalars(size_t count, size_t size)
test_instances_t< GroupT > generate_group_elements(size_t count, size_t size)
typename EC_ppT::Fp_type Fr
long long get_nsec_time()
Definition profiling.cpp:32
T multi_exp(typename std::vector< T >::const_iterator vec_start, typename std::vector< T >::const_iterator vec_end, typename std::vector< FieldT >::const_iterator scalar_start, typename std::vector< FieldT >::const_iterator scalar_end, const size_t chunks)
FieldT SHA512_rng(const uint64_t idx)
void print_compilation_info()
long long start_time
Definition profiling.cpp:53
uint16_t j