mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
added option to print wolfcrypt benchmark tests in CSV format
This commit is contained in:
@@ -422,6 +422,9 @@ static const bench_alg bench_other_opt[] = {
|
|||||||
#define SHOW_INTEL_CYCLES(b, n, s) \
|
#define SHOW_INTEL_CYCLES(b, n, s) \
|
||||||
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
|
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
|
||||||
count == 0 ? 0 : (float)total_cycles / ((word64)count*s))
|
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)
|
#elif defined(LINUX_CYCLE_COUNT)
|
||||||
#include <linux/perf_event.h>
|
#include <linux/perf_event.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
@@ -448,6 +451,9 @@ static const bench_alg bench_other_opt[] = {
|
|||||||
#define SHOW_INTEL_CYCLES(b, n, s) \
|
#define SHOW_INTEL_CYCLES(b, n, s) \
|
||||||
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
|
XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " Cycles per byte = %6.2f\n", \
|
||||||
(float)total_cycles / (count*s))
|
(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
|
#else
|
||||||
#define INIT_CYCLE_COUNTER
|
#define INIT_CYCLE_COUNTER
|
||||||
@@ -695,6 +701,10 @@ static int digest_stream = 1;
|
|||||||
static int rsa_sign_verify = 0;
|
static int rsa_sign_verify = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Don't print out in CSV format by default */
|
||||||
|
static int csv_format = 0;
|
||||||
|
static int csv_header_count = 0;
|
||||||
|
|
||||||
/* for compatibility */
|
/* for compatibility */
|
||||||
#define BENCH_SIZE bench_size
|
#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;
|
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,
|
desc, BENCH_ASYNC_GET_NAME(doAsync), blocks, blockType, total,
|
||||||
persec, blockType);
|
persec, blockType);
|
||||||
SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz);
|
SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz);
|
||||||
|
}
|
||||||
printf("%s", msg);
|
printf("%s", msg);
|
||||||
|
|
||||||
/* show errors */
|
/* show errors */
|
||||||
@@ -934,9 +950,19 @@ static void bench_stats_asym_finish(const char* algo, int strength,
|
|||||||
opsSec = count / total; /* ops second */
|
opsSec = count / total; /* ops second */
|
||||||
milliEach = each * 1000; /* milliseconds */
|
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),
|
" %.3f ops/sec\n", algo, strength, desc, BENCH_ASYNC_GET_NAME(doAsync),
|
||||||
count, total, milliEach, opsSec);
|
count, total, milliEach, opsSec);
|
||||||
|
}
|
||||||
|
|
||||||
/* show errors */
|
/* show errors */
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -1477,8 +1503,16 @@ int benchmark_init(void)
|
|||||||
wolfSSL_Debugging_ON();
|
wolfSSL_Debugging_ON();
|
||||||
#endif
|
#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);
|
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
|
#ifdef HAVE_WNR
|
||||||
ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
|
ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
|
||||||
@@ -4910,6 +4944,7 @@ static void Usage(void)
|
|||||||
|
|
||||||
printf("benchmark\n");
|
printf("benchmark\n");
|
||||||
printf("-? Help, print this usage\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");
|
printf("-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n");
|
||||||
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
||||||
printf("-no_aad No additional authentication data passed.\n");
|
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"))
|
else if (string_matches(argv[1], "-rsa_sign"))
|
||||||
rsa_sign_verify = 1;
|
rsa_sign_verify = 1;
|
||||||
#endif
|
#endif
|
||||||
|
else if (string_matches(argv[1], "-csv")) {
|
||||||
|
csv_format = 1;
|
||||||
|
}
|
||||||
else if (argv[1][0] == '-') {
|
else if (argv[1][0] == '-') {
|
||||||
optMatched = 0;
|
optMatched = 0;
|
||||||
#ifndef WOLFSSL_BENCHMARK_ALL
|
#ifndef WOLFSSL_BENCHMARK_ALL
|
||||||
|
Reference in New Issue
Block a user