]> git.codecow.com Git - Monocypher.git/commitdiff
More accurate speed benchmark
authorLoup Vaillant <loup@loup-vaillant.fr>
Sat, 3 Feb 2018 22:22:25 +0000 (23:22 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sat, 3 Feb 2018 23:59:36 +0000 (00:59 +0100)
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.

tests/speed-sodium.c
tests/speed.c
tests/speed.h

index 46c4768aac6b74394fc4b6d370f9f8583b993661..1da86b635c474bb5ce2a24a94a8f9621166837f0 100644 (file)
@@ -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;
 }
index 62b31e32698c12adb945ca3f529b8c6ad1072f76..a5b8635330f8a36560b7465c7744a7ef6b06c7aa 100644 (file)
@@ -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;
 }
index d91c2bfc334a78ee7447298623996a042bab2c3d..5f472211fa989f834dcc69a0bccd5bd30aa7f157 100644 (file)
@@ -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                              \