Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
benchmarks_main.c File Reference
#include <stdio.h>
#include <cgl_hash.h>
#include "benchmarks_utils.h"
#include <string.h>
#include <utilities.h>
Include dependency graph for benchmarks_main.c:

Go to the source code of this file.

Functions

void swap (ticks *a, ticks *b)
int partition (ticks arr[], int low, int high)
void quicksort (ticks arr[], int low, int high)
int main (int argc, char **argv)

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 55 of file benchmarks_main.c.

55 {
56
57 hal_init_perfcounters(1, 1);
58// const char * name_of_executable = strrchr(argv[0], '/');
59// printf("Test for %s!\n",name_of_executable);
60
61 // --------------------------
62 // For measuring clock cycles
63 ticks mark_min = 0xFFFFFFFFFFFFFFFF;
64 ticks mark_max = 0;
65 ticks mark_mean = 0;
66 ticks mark_two_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS] = {0};
67 ticks mark_three_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS] = {0};
68 ticks mark_0 = 0;
69 ticks mark_1 = 0;
70
71#if defined(NDEBUG)
72 ticks mark_current = 0;
73#endif
74
75 // -----------------------------------------------------
76 // 2-isogeny walks
77 cgl_hash_2_ctx ctx2;
78 fp2_t A, t;
79
82 fp2_add(&A, t, t);
83 fp2_add(&A, A, t);
84 fp2_add(&A, A, A);
85
86 cgl_hash_init_2(&ctx2, A);
87
88 //------------------------------------------------------
89 // Main loop
90
91 printf("\nNumbers correspond for \033[1;33mCGLHash2\033[0m.\n");
92 for (int i = 0; i < NUMBER_OF_BENCHMARK_EXPERIMENTS; i++) {
93 printf("// Running experiments:\t");
94 printf("%2d%%", 100 * i / NUMBER_OF_BENCHMARK_EXPERIMENTS);
95 fflush(stdout);
96 printf("\r\x1b[K");
97 // ----------------
98
99 uint8_t path[BIT_LENGTH_PATH / 8] = {0};
101
102 mark_0 = get_timestamp();
103 cgl_hash_digest_2(&A, &ctx2, path);
104 mark_1 = get_timestamp();
105
106 // ---------------------------------
107 // storing the measured clock cycles
108 mark_two_isogeny[i] = 0;
109 mark_two_isogeny[i] = mark_1 - mark_0;
110 // Minimum value
111 if(mark_min > mark_two_isogeny[i])
112 mark_min = mark_two_isogeny[i];
113 // Maximum value
114 if(mark_max < mark_two_isogeny[i])
115 mark_max = mark_two_isogeny[i];
116 // Average value
117 mark_mean += mark_two_isogeny[i];
118 }
119 mark_mean = mark_mean / NUMBER_OF_BENCHMARK_EXPERIMENTS;
120
121 printf("Average: \033[1;32m%llu\033[0m\n\n", (unsigned long long)mark_mean );
122
123#if defined(NDEBUG)
124 quicksort(mark_two_isogeny, 0, NUMBER_OF_BENCHMARK_EXPERIMENTS - 1);
125 // -----------------------------------------------------------
126 mark_current = mark_two_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 4];
127 printf("Q1: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
128 // -----------------------------------------------------------
129 mark_current = (mark_two_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 2] + mark_two_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 2 - 1]) / 2;
130 printf("Median: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
131 // -----------------------------------------------------------
132 mark_current = mark_two_isogeny[(3 * NUMBER_OF_BENCHMARK_EXPERIMENTS) / 4];
133 printf("Q3: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
134
135 // -----------------------------------------------------------
136 printf("\n");
137 printf("Min: \033[1;34m%llu\033[0m\n", (unsigned long long)mark_min );
138 printf("Max: \033[1;31m%llu\033[0m\n", (unsigned long long)mark_max );
139 printf("\n");
140#endif
141
142 //------------------------------------------------------
143 //------------------------------------------------------
144 // 3-isogeny walk
145
146 mark_min = 0xFFFFFFFFFFFFFFFF;
147 mark_max = 0;
148 mark_mean = 0;
149
150#if defined(NDEBUG)
151 mark_current = 0;
152#endif
153
154 cgl_hash_3_ctx ctx3;
155 fp2_set_to_zero(&A);
156 fp2_set_to_one(&t);
157 fp2_add(&A, t, t);
158 fp2_add(&A, A, t);
159 fp2_add(&A, A, A);
160
161 // For simplicity we take the first x-coordinate point
162 cgl_hash_init_3(&ctx3, A, 0);
163
164 //------------------------------------------------------
165 // Main loop
166
167 printf("Numbers correspond for \033[1;33mCGLHash3\033[0m.\n");
168 for (int i = 0; i < NUMBER_OF_BENCHMARK_EXPERIMENTS; i++) {
169 printf("// Running experiments:\t");
170 printf("%2d%%", 100 * i / NUMBER_OF_BENCHMARK_EXPERIMENTS);
171 fflush(stdout);
172 printf("\r\x1b[K");
173 // ----------------
174 uint8_t path[TRITLENGTH_PATH / 5] = {0};
176
177 mark_0 = get_timestamp();
178 cgl_hash_digest_3(&A, &ctx3, path);
179 mark_1 = get_timestamp();
180
181 // ---------------------------------
182 // storing the measured clock cycles
183 mark_three_isogeny[i] = 0;
184 mark_three_isogeny[i] = mark_1 - mark_0;
185 // Minimum value
186 if(mark_min > mark_three_isogeny[i])
187 mark_min = mark_three_isogeny[i];
188 // Maximum value
189 if(mark_max < mark_three_isogeny[i])
190 mark_max = mark_three_isogeny[i];
191 // Average value
192 mark_mean += mark_three_isogeny[i];
193 }
194 mark_mean = mark_mean / NUMBER_OF_BENCHMARK_EXPERIMENTS;
195
196 printf("Average: \033[1;32m%llu\033[0m\n\n", (unsigned long long)mark_mean );
197
198#if defined(NDEBUG)
199 quicksort(mark_three_isogeny, 0, NUMBER_OF_BENCHMARK_EXPERIMENTS - 1);
200 // -----------------------------------------------------------
201 mark_current = mark_three_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 4];
202 printf("Q1: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
203 // -----------------------------------------------------------
204 mark_current = (mark_three_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 2] + mark_three_isogeny[NUMBER_OF_BENCHMARK_EXPERIMENTS / 2 - 1]) / 2;
205 printf("Median: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
206 // -----------------------------------------------------------
207 mark_current = mark_three_isogeny[(3 * NUMBER_OF_BENCHMARK_EXPERIMENTS) / 4];
208 printf("Q3: \033[1;33m%llu\033[0m\n", (unsigned long long)mark_current );
209
210 // -----------------------------------------------------------
211 printf("\n");
212 printf("Min: \033[1;34m%llu\033[0m\n", (unsigned long long)mark_min );
213 printf("Max: \033[1;31m%llu\033[0m\n", (unsigned long long)mark_max );
214 printf("\n");
215#endif
216
217 char benchmarks_statistics_file_name[256];
218
219 strcpy(benchmarks_statistics_file_name, "BENCH-STATS-");
220
221#if defined(CYCLES)
222 strcat(benchmarks_statistics_file_name, "CLOCK-CYCLES-");
223#elif defined(TIME)
224 strcat(benchmarks_statistics_file_name, "NANOSECONDS-");
225#endif
226
227 strcat(benchmarks_statistics_file_name, FIELD_NAME);
228 strcat(benchmarks_statistics_file_name, ".csv");
229
230 printStatisticsFile(benchmarks_statistics_file_name, mark_two_isogeny, mark_three_isogeny);
231
232 return 0;
233}
void quicksort(ticks arr[], int low, int high)
void printStatisticsFile(const char *file_name, ticks *two_isogeny_walk, ticks *three_isogeny_walk)
void fp2_set_to_zero(fp2_t *output)
Definition fp2.c:54
void fp2_set_to_one(fp2_t *output)
Definition fp2.c:49
void isogeny_walks_sample_bit_string(uint8_t *output)
void isogeny_walks_sample_trit_string(uint8_t *output)
void cgl_hash_digest_3(fp2_t *output, const cgl_hash_3_ctx *ctx, const uint8_t *input_trit_string)
Definition cgl_hash.c:23
void cgl_hash_digest_2(fp2_t *output, const cgl_hash_2_ctx *ctx, const uint8_t *input_bitstring)
Definition cgl_hash.c:9
void cgl_hash_init_2(cgl_hash_2_ctx *ctx, fp2_t input_A)
Definition cgl_hash.c:16
void cgl_hash_init_3(cgl_hash_3_ctx *ctx, fp2_t input_A, uint8_t choice)
Definition cgl_hash.c:32
A
Definition tests.py:29
#define TRITLENGTH_PATH
Definition p254.h:15
#define FIELD_NAME
Definition p254.h:6
#define BIT_LENGTH_PATH
Definition p254.h:14
for i
Definition fp2.h:10
#define NUMBER_OF_BENCHMARK_EXPERIMENTS
Definition utilities.h:15

References BIT_LENGTH_PATH, cgl_hash_digest_2(), cgl_hash_digest_3(), cgl_hash_init_2(), cgl_hash_init_3(), FIELD_NAME, fp2_add, fp2_set_to_one(), fp2_set_to_zero(), i, isogeny_walks_sample_bit_string(), isogeny_walks_sample_trit_string(), NUMBER_OF_BENCHMARK_EXPERIMENTS, printStatisticsFile(), quicksort(), and TRITLENGTH_PATH.

Here is the call graph for this function:

◆ partition()

int partition ( ticks arr[],
int low,
int high )

Definition at line 20 of file benchmarks_main.c.

20 {
21 ticks pivot = arr[high]; // pivot
22 int i = (low - 1); // Index of smaller element
23
24 int j;
25 for(j = low; j <= high- 1; j++)
26 {
27 // If current element is smaller than the pivot
28 if(arr[j] < pivot)
29 {
30 i++; // increment index of smaller element
31 swap(&arr[i], &arr[j]);
32 }
33 }
34 swap(&arr[i + 1], &arr[high]);
35 return (i + 1);
36}
void swap(ticks *a, ticks *b)
for j

References i, j, and swap().

Referenced by quicksort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quicksort()

void quicksort ( ticks arr[],
int low,
int high )

Definition at line 42 of file benchmarks_main.c.

42 {
43 if (low < high)
44 {
45 /* pi is partitioning index, arr[p] is now at right place */
46 int pi = partition(arr, low, high);
47
48 // Separately sort elements before
49 // partition and after partition
50 quicksort(arr, low, pi - 1);
51 quicksort(arr, pi + 1, high);
52 }
53}
int partition(ticks arr[], int low, int high)

References partition(), and quicksort().

Referenced by main(), and quicksort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

void swap ( ticks * a,
ticks * b )

Definition at line 9 of file benchmarks_main.c.

9 {
10 ticks t = *a;
11 *a = *b;
12 *b = t;
13}
f a
Definition to_model.m:12

References a.

Referenced by action(), and partition().

Here is the caller graph for this function: