@@ -34,67 +34,6 @@ static int64_t gettime_i64(void) {
3434#endif
3535}
3636
37- #define FP_EXP (6)
38- #define FP_MULT (1000000LL)
39-
40- /* Format fixed point number. */
41- static void print_number (const int64_t x ) {
42- int64_t x_abs , y ;
43- int c , i , rounding , g ; /* g = integer part size, c = fractional part size */
44- size_t ptr ;
45- char buffer [30 ];
46-
47- if (x == INT64_MIN ) {
48- /* Prevent UB. */
49- printf ("ERR" );
50- return ;
51- }
52- x_abs = x < 0 ? - x : x ;
53-
54- /* Determine how many decimals we want to show (more than FP_EXP makes no
55- * sense). */
56- y = x_abs ;
57- c = 0 ;
58- while (y > 0LL && y < 100LL * FP_MULT && c < FP_EXP ) {
59- y *= 10LL ;
60- c ++ ;
61- }
62-
63- /* Round to 'c' decimals. */
64- y = x_abs ;
65- rounding = 0 ;
66- for (i = c ; i < FP_EXP ; ++ i ) {
67- rounding = (y % 10 ) >= 5 ;
68- y /= 10 ;
69- }
70- y += rounding ;
71-
72- /* Format and print the number. */
73- ptr = sizeof (buffer ) - 1 ;
74- buffer [ptr ] = 0 ;
75- g = 0 ;
76- if (c != 0 ) { /* non zero fractional part */
77- for (i = 0 ; i < c ; ++ i ) {
78- buffer [-- ptr ] = '0' + (y % 10 );
79- y /= 10 ;
80- }
81- } else if (c == 0 ) { /* fractional part is 0 */
82- buffer [-- ptr ] = '0' ;
83- }
84- buffer [-- ptr ] = '.' ;
85- do {
86- buffer [-- ptr ] = '0' + (y % 10 );
87- y /= 10 ;
88- g ++ ;
89- } while (y != 0 );
90- if (x < 0 ) {
91- buffer [-- ptr ] = '-' ;
92- g ++ ;
93- }
94- printf ("%5.*s" , g , & buffer [ptr ]); /* Prints integer part */
95- printf ("%-*s" , FP_EXP , & buffer [ptr + g ]); /* Prints fractional part */
96- }
97-
9837static void run_benchmark (char * name , void (* benchmark )(void * , int ), void (* setup )(void * ), void (* teardown )(void * , int ), void * data , int count , int iter ) {
9938 int i ;
10039 int64_t min = INT64_MAX ;
@@ -120,13 +59,7 @@ static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setu
12059 sum += total ;
12160 }
12261 /* ',' is used as a column delimiter */
123- printf ("%-30s, " , name );
124- print_number (min * FP_MULT / iter );
125- printf (" , " );
126- print_number (((sum * FP_MULT ) / count ) / iter );
127- printf (" , " );
128- print_number (max * FP_MULT / iter );
129- printf ("\n" );
62+ printf ("%-30s, %-15.1f, %-15.1f, %-15.1f\n" , name , (double )min / iter , (double )sum / count / iter , (double )max / iter );
13063}
13164
13265static int have_flag (int argc , char * * argv , char * flag ) {
@@ -177,12 +110,11 @@ static int get_iters(int default_iters) {
177110}
178111
179112static void print_output_table_header_row (void ) {
180- char * bench_str = "Benchmark" ; /* left justified */
181- char * min_str = " Min(us) " ; /* center alignment */
182- char * avg_str = " Avg(us) " ;
183- char * max_str = " Max(us) " ;
184- printf ("%-30s,%-15s,%-15s,%-15s\n" , bench_str , min_str , avg_str , max_str );
185- printf ("\n" );
113+ char * bench_str = "Benchmark" ;
114+ char * min_str = "Min(us)" ;
115+ char * avg_str = "Avg(us)" ;
116+ char * max_str = "Max(us)" ;
117+ printf ("%-30s,%-15s,%-15s,%-15s\n\n" , bench_str , min_str , avg_str , max_str );
186118}
187119
188120#endif /* SECP256K1_BENCH_H */
0 commit comments