@@ -1051,7 +1051,12 @@ static const char* bench_Usage_msg1[][22] = {
10511051#endif
10521052
10531053static const char * bench_result_words1 [][4 ] = {
1054- { "took" , "seconds" , "Cycles per byte" , NULL }, /* 0 English */
1054+ #ifdef BENCH_MICROSECOND
1055+ { "took" , "microseconds" , "Cycles per byte" , NULL }, /* 0 English for
1056+ mircroseconds */
1057+ #else
1058+ { "took" , "seconds" , "Cycles per byte" , NULL }, /* 0 English */
1059+ #endif
10551060#ifndef NO_MULTIBYTE_PRINT
10561061 { "を" , "秒で処理" , "1バイトあたりのサイクル数" , NULL }, /* 1 Japanese */
10571062#endif
@@ -1317,7 +1322,12 @@ static const char* bench_desc_words[][15] = {
13171322 defined(HAVE_CURVE448 ) || defined(HAVE_ED448 ) || \
13181323 defined(WOLFSSL_HAVE_KYBER )
13191324static const char * bench_result_words2 [][5 ] = {
1325+ #ifdef BENCH_MICROSECOND
1326+ { "ops took" , "μsec" , "avg" , "ops/μsec" , NULL }, /* 0 English
1327+ for μsec */
1328+ #else
13201329 { "ops took" , "sec" , "avg" , "ops/sec" , NULL }, /* 0 English */
1330+ #endif
13211331#ifndef NO_MULTIBYTE_PRINT
13221332 { "回処理を" , "秒で実施" , "平均" , "処理/秒" , NULL }, /* 1 Japanese */
13231333#endif
@@ -1834,7 +1844,11 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
18341844
18351845static WC_INLINE int bench_stats_check (double start )
18361846{
1837- return ((current_time (0 ) - start ) < BENCH_MIN_RUNTIME_SEC );
1847+ return ((current_time (0 ) - start ) < BENCH_MIN_RUNTIME_SEC
1848+ #ifdef BENCH_MICROSECOND
1849+ * 1000000
1850+ #endif
1851+ );
18381852}
18391853
18401854/* return text for units and scale the value of blocks as needed */
@@ -1931,9 +1945,11 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
19311945{
19321946 double total , persec = 0 , blocks = (double )count ;
19331947 const char * blockType ;
1948+ const char * timeUnit ;
19341949 char msg [WC_BENCH_MAX_LINE_LEN ];
19351950 const char * * word = bench_result_words1 [lng_index ];
19361951 static int sym_header_printed = 0 ;
1952+ int timeDigits ;
19371953
19381954 XMEMSET (msg , 0 , sizeof (msg ));
19391955
@@ -1991,6 +2007,14 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
19912007 }
19922008 }
19932009
2010+ #ifdef BENCH_MICROSECOND
2011+ timeUnit = "μs" ;
2012+ timeDigits = 8 ;
2013+ #else
2014+ timeUnit = "s" ;
2015+ timeDigits = 3 ;
2016+ #endif
2017+
19942018 /* determine if we have fixed units, or auto-scale bits or bytes for units.
19952019 * note that the blockType text is assigned AND the blocks param is scaled.
19962020 */
@@ -2070,29 +2094,31 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
20702094 #ifdef HAVE_GET_CYCLES
20712095 (void )XSNPRINTF (msg , sizeof (msg ),
20722096 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
2073- FLT_FMT_PREC2 " %s/s, %lu cycles," ,
2097+ FLT_FMT_PREC2 " %s/% s, %lu cycles," ,
20742098 desc , BENCH_DEVID_GET_NAME (useDeviceID ),
20752099 FLT_FMT_PREC2_ARGS (5 , 0 , blocks ), blockType ,
20762100 word [0 ], FLT_FMT_PREC2_ARGS (5 , 3 , total ), word [1 ],
2077- FLT_FMT_PREC2_ARGS (8 , 3 , persec ), blockType ,
2101+ FLT_FMT_PREC2_ARGS (8 , timeDigits , persec ), blockType , timeUnit
20782102 (unsigned long ) total_cycles );
20792103 #else
20802104 (void )XSNPRINTF (msg , sizeof (msg ),
20812105 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
2082- FLT_FMT_PREC2 " %s/s," ,
2106+ FLT_FMT_PREC2 " %s/% s," ,
20832107 desc , BENCH_DEVID_GET_NAME (useDeviceID ),
20842108 FLT_FMT_PREC2_ARGS (5 , 0 , blocks ), blockType ,
20852109 word [0 ], FLT_FMT_PREC2_ARGS (5 , 3 , total ), word [1 ],
2086- FLT_FMT_PREC2_ARGS (8 , 3 , persec ), blockType );
2110+ FLT_FMT_PREC2_ARGS (8 , timeDigits , persec ), blockType ,
2111+ timeUnit );
20872112 #endif /* HAVE_GET_CYCLES */
20882113#else
20892114 (void )XSNPRINTF (msg , sizeof (msg ),
20902115 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
2091- FLT_FMT_PREC2 " %s/s" ,
2116+ FLT_FMT_PREC2 " %s/% s" ,
20922117 desc , BENCH_DEVID_GET_NAME (useDeviceID ),
20932118 FLT_FMT_PREC2_ARGS (5 , 0 , blocks ), blockType ,
20942119 word [0 ], FLT_FMT_PREC2_ARGS (5 , 3 , total ), word [1 ],
2095- FLT_FMT_PREC2_ARGS (8 , 3 , persec ), blockType );
2120+ FLT_FMT_PREC2_ARGS (8 , timeDigits , persec ), blockType ,
2121+ timeUnit );
20962122#endif
20972123
20982124#ifdef WOLFSSL_ESPIDF
@@ -2179,8 +2205,13 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
21792205 opsSec = 0 ;
21802206 }
21812207
2208+ #ifdef BENCH_MICROSECOND
2209+ milliEach = each / 1000 ; /* milliseconds */
2210+ #else
21822211 milliEach = each * 1000 ; /* milliseconds */
21832212
2213+ #endif
2214+
21842215 SLEEP_ON_ERROR (ret );
21852216 /* format and print to terminal */
21862217 if (csv_format == 1 ) {
@@ -10350,7 +10381,11 @@ void bench_sphincsKeySign(byte level, byte optim)
1035010381
1035110382 QueryPerformanceCounter (& count );
1035210383
10384+ #ifdef BENCH_MICROSECOND
10385+ return ((double )count .QuadPart * 1000000 ) / freq .QuadPart ;
10386+ #else
1035310387 return (double )count .QuadPart / freq .QuadPart ;
10388+ #endif
1035410389 }
1035510390
1035610391#elif defined MICROCHIP_PIC32
@@ -10612,7 +10647,11 @@ void bench_sphincsKeySign(byte level, byte optim)
1061210647
1061310648 LIBCALL_CHECK_RET (gettimeofday (& tv , 0 ));
1061410649
10650+ #ifdef BENCH_MICROSECOND
10651+ return (double )tv .tv_sec * 1000000 + (double )tv .tv_usec ;
10652+ #else
1061510653 return (double )tv .tv_sec + (double )tv .tv_usec / 1000000 ;
10654+ #endif
1061610655 }
1061710656
1061810657#endif /* _WIN32 */
0 commit comments