added option to print wolfcrypt benchmark tests in CSV format

This commit is contained in:
MJSPollard
2018-09-11 14:49:54 -06:00
parent f90b7d6c37
commit d280359548

View File

@@ -422,6 +422,9 @@ static const bench_alg bench_other_opt[] = {
#define SHOW_INTEL_CYCLES(b, n, s) \
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
count == 0 ? 0 : (float)total_cycles / ((word64)count*s))
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.2f,\n", \
count == 0 ? 0 : (float)total_cycles / ((word64)count*s))
#elif defined(LINUX_CYCLE_COUNT)
#include <linux/perf_event.h>
#include <sys/syscall.h>
@@ -448,6 +451,9 @@ static const bench_alg bench_other_opt[] = {
#define SHOW_INTEL_CYCLES(b, n, s) \
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
(float)total_cycles / (count*s))
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.2f,\n", \
(float)total_cycles / (count*s))
#else
#define INIT_CYCLE_COUNTER
@@ -695,6 +701,10 @@ static int digest_stream = 1;
static int rsa_sign_verify = 0;
#endif
/* Don't print out in CSV format by default */
static int csv_format = 0;
static int csv_header_count = 0;
/* for compatibility */
#define BENCH_SIZE bench_size
@@ -902,10 +912,16 @@ static void bench_stats_sym_finish(const char* desc, int doAsync, int count,
persec = (1 / total) * blocks;
}
XSNPRINTF(msg, sizeof(msg), "%-16s%s %5.0f %s took %5.3f seconds, %8.3f %s/s",
/* format and print to terminal */
if (csv_format == 1) {
XSNPRINTF(msg, sizeof(msg), "%s,%.3f,", desc, persec);
SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), countSz);
} else {
XSNPRINTF(msg, sizeof(msg), "%-16s%s %5.0f %s took %5.3f seconds, %8.3f %s/s",
desc, BENCH_ASYNC_GET_NAME(doAsync), blocks, blockType, total,
persec, blockType);
SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz);
SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz);
}
printf("%s", msg);
/* show errors */
@@ -934,9 +950,19 @@ static void bench_stats_asym_finish(const char* algo, int strength,
opsSec = count / total; /* ops second */
milliEach = each * 1000; /* milliseconds */
printf("%-6s %5d %-9s %s %6d ops took %5.3f sec, avg %5.3f ms,"
/* format and print to terminal */
if (csv_format == 1) {
if (csv_header_count == 0) {
printf("\nAsymmetric Ciphers:\n\n");
printf("Algorithm,avg ms,ops/sec,\n");
csv_header_count++;
}
printf("%s %d %s,%.3f,%.3f,\n", algo, strength, desc, milliEach, opsSec);
} else {
printf("%-6s %5d %-9s %s %6d ops took %5.3f sec, avg %5.3f ms,"
" %.3f ops/sec\n", algo, strength, desc, BENCH_ASYNC_GET_NAME(doAsync),
count, total, milliEach, opsSec);
}
/* show errors */
if (ret < 0) {
@@ -1477,8 +1503,16 @@ int benchmark_init(void)
wolfSSL_Debugging_ON();
#endif
printf("wolfCrypt Benchmark (block bytes %d, min %.1f sec each)\n",
if (csv_format == 1) {
printf("wolfCrypt Benchmark (block bytes %d, min %.1f sec each)\n",
BENCH_SIZE, BENCH_MIN_RUNTIME_SEC);
printf("This format allows you to easily copy the output to a csv file.");
printf("\n\nSymmetric Ciphers:\n\n");
printf("Algorithm,MB/s,Cycles per byte,\n");
} else {
printf("wolfCrypt Benchmark (block bytes %d, min %.1f sec each)\n",
BENCH_SIZE, BENCH_MIN_RUNTIME_SEC);
}
#ifdef HAVE_WNR
ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
@@ -4910,6 +4944,7 @@ static void Usage(void)
printf("benchmark\n");
printf("-? Help, print this usage\n");
printf("-csv Print terminal output in csv format\n");
printf("-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n");
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
printf("-no_aad No additional authentication data passed.\n");
@@ -4983,6 +5018,9 @@ int main(int argc, char** argv)
else if (string_matches(argv[1], "-rsa_sign"))
rsa_sign_verify = 1;
#endif
else if (string_matches(argv[1], "-csv")) {
csv_format = 1;
}
else if (argv[1][0] == '-') {
optMatched = 0;
#ifndef WOLFSSL_BENCHMARK_ALL