]> git.codecow.com Git - Monocypher.git/commitdiff
Factored speed tests
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 2 Jan 2018 22:59:05 +0000 (23:59 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 2 Jan 2018 22:59:05 +0000 (23:59 +0100)
makefile
tests/speed-sodium.c
tests/speed.c
tests/speed.h [new file with mode: 0644]

index 3b2b1a1dac7bdd463fb5115d5997152eabdaac97..7b4000d09e95662c3a411e9123190b4b3ec523c0 100644 (file)
--- a/makefile
+++ b/makefile
@@ -80,19 +80,21 @@ lib/monocypher.o lib/sha512.o:
 
 # Test & speed libraries
 $TEST_COMMON=tests/utils.h src/monocypher.h src/optional/sha512.h
-lib/utils.o: tests/utils.c tests/utils.h
-lib/test.o : tests/test.c  $(TEST_COMMON) tests/vectors.h
-lib/speed.o: tests/speed.c $(TEST_COMMON)
-lib/utils.o lib/test.o lib/speed.o:
+lib/utils.o       : tests/utils.c tests/utils.h
+lib/test.o        : tests/test.c         $(TEST_COMMON) tests/vectors.h
+lib/speed.o       : tests/speed.c        $(TEST_COMMON) tests/speed.h
+lib/speed-sodium.o: tests/speed-sodium.c $(TEST_COMMON) tests/speed.h
+lib/utils.o lib/test.o lib/speed.o lib/speed-sodium.o:
        @mkdir -p $(@D)
        $(CC) $(CFLAGS) -I src -I src/optional -fPIC -c -o $@ $<
 
 # test & speed executables
-test.out : lib/test.o  lib/monocypher.o lib/sha512.o lib/utils.o
-speed.out: lib/speed.o lib/monocypher.o lib/sha512.o lib/utils.o
+test.out        : lib/test.o         lib/utils.o lib/monocypher.o lib/sha512.o
+speed.out       : lib/speed.o        lib/utils.o lib/monocypher.o lib/sha512.o
+speed-sodium.out: lib/speed-sodium.o lib/utils.o
 test.out speed.out:
        $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^
-speed-sodium.out: tests/speed-sodium.c lib/utils.o
+speed-sodium.out: lib/speed-sodium.o lib/utils.o
        $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^ \
             $$(pkg-config --cflags libsodium)           \
             $$(pkg-config --libs   libsodium)
index 97e174710b9542c7ba82e8448c410d6930929901..4e188cff4864eda56971267bbdcacc3b2d88b56a 100644 (file)
@@ -1,70 +1,5 @@
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "speed.h"
 #include "sodium.h"
-#include "utils.h"
-
-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)
-
-timespec diff(timespec start, timespec end)
-{
-    timespec duration;
-    duration.tv_sec  = end.tv_sec  - start.tv_sec;
-    duration.tv_nsec = end.tv_nsec - start.tv_nsec;
-    if (duration.tv_nsec < 0) {
-        duration.tv_nsec += 1000000000;
-        duration.tv_sec  -= 1;
-    }
-    return duration;
-}
-
-timespec min(timespec a, timespec b)
-{
-    if (a.tv_sec < b.tv_sec ||
-        (a.tv_sec == b.tv_sec && a.tv_nsec < b.tv_nsec)) {
-        return a;
-    }
-    return b;
-}
-
-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);
-}
-
-static void print(const char *name, u64 speed, const char *unit)
-{
-    printf("%s: %5" PRIu64 " %s\n", name, speed, unit);
-}
-
-// TODO: adjust this crap
-#define TIMESTAMP(t)                            \
-    timespec t;                                 \
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t)
-
-#define TIMING_START                            \
-    timespec duration;                          \
-    duration.tv_sec = -1;                       \
-    duration.tv_nsec = -1;                      \
-    duration.tv_sec  = 3600 * 24;               \
-    duration.tv_nsec = 0;                       \
-    FOR (i, 0, 10) {                            \
-        TIMESTAMP(start);
-
-#define TIMING_END                              \
-    TIMESTAMP(end);                             \
-    duration = min(duration, diff(start, end)); \
-    } /* end FOR*/                              \
-    return speed(duration)
 
 static u64 chacha20(void)
 {
index 787f8e8ae296efe296509eaf64427d04ef30ed24..cd9eb5bbc3845494a63a5953b329c4d7e6c02450 100644 (file)
@@ -1,73 +1,8 @@
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "speed.h"
 #include "monocypher.h"
 #include "sha512.h"
 #include "utils.h"
 
-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)
-
-timespec diff(timespec start, timespec end)
-{
-    timespec duration;
-    duration.tv_sec  = end.tv_sec  - start.tv_sec;
-    duration.tv_nsec = end.tv_nsec - start.tv_nsec;
-    if (duration.tv_nsec < 0) {
-        duration.tv_nsec += 1000000000;
-        duration.tv_sec  -= 1;
-    }
-    return duration;
-}
-
-timespec min(timespec a, timespec b)
-{
-    if (a.tv_sec < b.tv_sec ||
-        (a.tv_sec == b.tv_sec && a.tv_nsec < b.tv_nsec)) {
-        return a;
-    }
-    return b;
-}
-
-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);
-}
-
-static void print(const char *name, u64 speed, const char *unit)
-{
-    printf("%s: %4" PRIu64 " %s\n", name, speed, unit);
-}
-
-// TODO: adjust this crap
-#define TIMESTAMP(t)                            \
-    timespec t;                                 \
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t)
-
-#define TIMING_START                            \
-    timespec duration;                          \
-    duration.tv_sec = -1;                       \
-    duration.tv_nsec = -1;                      \
-    duration.tv_sec  = 3600 * 24;               \
-    duration.tv_nsec = 0;                       \
-    FOR (i, 0, 10) {                            \
-        TIMESTAMP(start);
-
-#define TIMING_END                              \
-    TIMESTAMP(end);                             \
-    duration = min(duration, diff(start, end)); \
-    } /* end FOR*/                              \
-    return speed(duration)
-
-
 static u64 chacha20(void)
 {
     static u8  in   [SIZE];  p_random(in   , SIZE);
diff --git a/tests/speed.h b/tests/speed.h
new file mode 100644 (file)
index 0000000..d91c2bf
--- /dev/null
@@ -0,0 +1,65 @@
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "utils.h"
+
+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)
+
+static timespec diff(timespec start, timespec end)
+{
+    timespec duration;
+    duration.tv_sec  = end.tv_sec  - start.tv_sec;
+    duration.tv_nsec = end.tv_nsec - start.tv_nsec;
+    if (duration.tv_nsec < 0) {
+        duration.tv_nsec += 1000000000;
+        duration.tv_sec  -= 1;
+    }
+    return duration;
+}
+
+static timespec min(timespec a, timespec b)
+{
+    if (a.tv_sec < b.tv_sec ||
+        (a.tv_sec == b.tv_sec && a.tv_nsec < b.tv_nsec)) {
+        return a;
+    }
+    return 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);
+}
+
+static void print(const char *name, u64 speed, const char *unit)
+{
+    printf("%s: %5" PRIu64 " %s\n", name, speed, unit);
+}
+
+#define TIMESTAMP(t)                            \
+    timespec t;                                 \
+    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t)
+
+#define TIMING_START                            \
+    timespec duration;                          \
+    duration.tv_sec = -1;                       \
+    duration.tv_nsec = -1;                      \
+    duration.tv_sec  = 3600 * 24;               \
+    duration.tv_nsec = 0;                       \
+    FOR (i, 0, 10) {                            \
+        TIMESTAMP(start);
+
+#define TIMING_END                              \
+    TIMESTAMP(end);                             \
+    duration = min(duration, diff(start, end)); \
+    } /* end FOR*/                              \
+    return speed(duration)