Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
multiexp_profile.cpp File Reference
Include dependency graph for multiexp_profile.cpp:

Go to the source code of this file.

Typedefs

template<typename GroupT >
using run_result_t = std::pair<long long, std::vector<GroupT> >
 
template<typename T >
using test_instances_t = std::vector<std::vector<T> >
 

Functions

template<typename GroupT >
test_instances_t< GroupT > generate_group_elements (size_t count, size_t size)
 
template<typename FieldT >
test_instances_t< FieldT > generate_scalars (size_t count, size_t size)
 
template<typename GroupT , typename FieldT , multi_exp_method Method>
run_result_t< GroupT > profile_multiexp (test_instances_t< GroupT > group_elements, test_instances_t< FieldT > scalars)
 
template<typename GroupT , typename FieldT >
void print_performance_csv (size_t expn_start, size_t expn_end_fast, size_t expn_end_naive, bool compare_answers)
 
int main (void)
 

Typedef Documentation

◆ run_result_t

template<typename GroupT >
using run_result_t = std::pair<long long, std::vector<GroupT> >

Definition at line 12 of file multiexp_profile.cpp.

◆ test_instances_t

template<typename T >
using test_instances_t = std::vector<std::vector<T> >

Definition at line 15 of file multiexp_profile.cpp.

Function Documentation

◆ generate_group_elements()

template<typename GroupT >
test_instances_t< GroupT > generate_group_elements ( size_t count,
size_t size )

Definition at line 18 of file multiexp_profile.cpp.

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}
int * count
std::vector< std::vector< T > > test_instances_t
uint16_t j
Here is the caller graph for this function:

◆ generate_scalars()

template<typename FieldT >
test_instances_t< FieldT > generate_scalars ( size_t count,
size_t size )

Definition at line 37 of file multiexp_profile.cpp.

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}
FieldT SHA512_rng(const uint64_t idx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 116 of file multiexp_profile.cpp.

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
void print_performance_csv(size_t expn_start, size_t expn_end_fast, size_t expn_end_naive, bool compare_answers)
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
typename EC_ppT::Fp_type Fr
void print_compilation_info()
Here is the call graph for this function:

◆ print_performance_csv()

template<typename GroupT , typename FieldT >
void print_performance_csv ( size_t expn_start,
size_t expn_end_fast,
size_t expn_end_naive,
bool compare_answers )

Definition at line 73 of file multiexp_profile.cpp.

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}
std::pair< long long, std::vector< GroupT > > run_result_t
run_result_t< GroupT > profile_multiexp(test_instances_t< GroupT > group_elements, test_instances_t< FieldT > scalars)
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ profile_multiexp()

template<typename GroupT , typename FieldT , multi_exp_method Method>
run_result_t< GroupT > profile_multiexp ( test_instances_t< GroupT > group_elements,
test_instances_t< FieldT > scalars )

Definition at line 53 of file multiexp_profile.cpp.

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}
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)
long long start_time
Definition profiling.cpp:53
Here is the call graph for this function:
Here is the caller graph for this function: