From: Loup Vaillant Date: Sat, 3 Feb 2018 22:22:25 +0000 (+0100) Subject: More accurate speed benchmark X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=e13215c8d16e094eaed131f80c529edef4d4ae10;p=Monocypher.git More accurate speed benchmark Used smaller buffers to minimise the impact of cache misses in the benchmark. Chosen a size that makes Libsodium and Monocypher look best. (There is a trade-off between start up time and throughput.) This should highlight the algorithmic differences better. Still, the memory access patterns are very clean, computation tends to dominate. Ultimately, this makes little difference. --- diff --git a/tests/speed-sodium.c b/tests/speed-sodium.c index 46c4768..1da86b6 100644 --- a/tests/speed-sodium.c +++ b/tests/speed-sodium.c @@ -124,15 +124,15 @@ static u64 edDSA_check(void) int main() { SODIUM_INIT; - print("Chacha20 ",chacha20() *MULT/DIV,"megabytes per second"); - print("Poly1305 ",poly1305() *MULT/DIV,"megabytes per second"); - print("Auth'd encryption",authenticated()*MULT/DIV,"megabytes per second"); - print("Blake2b ",blake2b() *MULT/DIV,"megabytes per second"); - print("Sha512 ",sha512() *MULT/DIV,"megabytes per second"); - print("Argon2i, 3 passes",argon2i() *MULT/DIV,"megabytes per second"); - print("x25519 ",x25519() /DIV,"exchanges per second"); - print("EdDSA(sign) ",edDSA_sign() /DIV,"signatures per second"); - print("EdDSA(check) ",edDSA_check() /DIV,"checks per second"); + print("Chacha20 ",chacha20() /DIV,"megabytes per second"); + print("Poly1305 ",poly1305() /DIV,"megabytes per second"); + print("Auth'd encryption",authenticated()/DIV,"megabytes per second"); + print("Blake2b ",blake2b() /DIV,"megabytes per second"); + print("Sha512 ",sha512() /DIV,"megabytes per second"); + print("Argon2i, 3 passes",argon2i() /DIV,"megabytes per second"); + print("x25519 ",x25519() ,"exchanges per second"); + print("EdDSA(sign) ",edDSA_sign() ,"signatures per second"); + print("EdDSA(check) ",edDSA_check() ,"checks per second"); printf("\n"); return 0; } diff --git a/tests/speed.c b/tests/speed.c index 62b31e3..a5b8635 100644 --- a/tests/speed.c +++ b/tests/speed.c @@ -127,15 +127,15 @@ static u64 edDSA_check(void) int main() { - print("Chacha20 ",chacha20() *MULT/DIV,"megabytes per second"); - print("Poly1305 ",poly1305() *MULT/DIV,"megabytes per second"); - print("Auth'd encryption",authenticated()*MULT/DIV,"megabytes per second"); - print("Blake2b ",blake2b() *MULT/DIV,"megabytes per second"); - print("Sha512 ",sha512() *MULT/DIV,"megabytes per second"); - print("Argon2i, 3 passes",argon2i() *MULT/DIV,"megabytes per second"); - print("x25519 ",x25519() /DIV,"exchanges per second"); - print("EdDSA(sign) ",edDSA_sign() /DIV,"signatures per second"); - print("EdDSA(check) ",edDSA_check() /DIV,"checks per second"); + print("Chacha20 ",chacha20() /DIV,"megabytes per second"); + print("Poly1305 ",poly1305() /DIV,"megabytes per second"); + print("Auth'd encryption",authenticated()/DIV,"megabytes per second"); + print("Blake2b ",blake2b() /DIV,"megabytes per second"); + print("Sha512 ",sha512() /DIV,"megabytes per second"); + print("Argon2i, 3 passes",argon2i() /DIV,"megabytes per second"); + print("x25519 ",x25519() ,"exchanges per second"); + print("EdDSA(sign) ",edDSA_sign() ,"signatures per second"); + print("EdDSA(check) ",edDSA_check() ,"checks per second"); printf("\n"); return 0; } diff --git a/tests/speed.h b/tests/speed.h index d91c2bf..5f47221 100644 --- a/tests/speed.h +++ b/tests/speed.h @@ -8,9 +8,9 @@ typedef struct timespec timespec; // TODO: provide a user defined buffer size #define KILOBYTE 1024 -#define MEGABYTE (1024 * KILOBYTE) -#define SIZE (50 * MEGABYTE) -#define MULT (SIZE / MEGABYTE) +#define MEGABYTE 1024 * KILOBYTE +#define SIZE (256 * KILOBYTE) +#define DIV (MEGABYTE / SIZE) static timespec diff(timespec start, timespec end) { @@ -35,9 +35,8 @@ static timespec min(timespec a, timespec b) static u64 speed(timespec duration) { -#define DIV 1000 // avoid round errors static const u64 giga = 1000000000; - return DIV * giga / (duration.tv_nsec + duration.tv_sec * giga); + return giga / (duration.tv_nsec + duration.tv_sec * giga); } static void print(const char *name, u64 speed, const char *unit) @@ -55,7 +54,7 @@ static void print(const char *name, u64 speed, const char *unit) duration.tv_nsec = -1; \ duration.tv_sec = 3600 * 24; \ duration.tv_nsec = 0; \ - FOR (i, 0, 10) { \ + FOR (i, 0, 500) { \ TIMESTAMP(start); #define TIMING_END \