Welcome to little lamb

Code » test-hashes » commit ef2850e

Remove some magic numbers

author Olivier Brunel
2023-02-03 16:50:11 UTC
committer Olivier Brunel
2023-02-03 16:50:11 UTC
parent e15dc56f52a336896ab0c6b504a5f60b2f312f1a

Remove some magic numbers

src/test.c +8 -5

diff --git a/src/test.c b/src/test.c
index 97c4c8e..e8e3818 100644
--- a/src/test.c
+++ b/src/test.c
@@ -29,19 +29,22 @@ extern void update(const char *msg, size_t size);
 extern void final(unsigned char *md);
 extern int hashlen(void);
 
+#define SIZE    (512 << 10)
+#define BLOCKS  20
+#define ITER    100
 int main(void)
 {
     struct timespec ts1, ts2;
-    char msg[512 << 10];
+    char msg[SIZE];
     unsigned char md[64] = { 0 };
 
-    for (int i = 512 << 10; i; --i)
+    for (int i = SIZE; i; --i)
         msg[i] = i % 256;
 
     clock_gettime(CLOCK_MONOTONIC, &ts1);
-    for (int iter = 0; iter < 100; ++iter) {
+    for (int iter = 0; iter < ITER; ++iter) {
         init();
-        for (int i = 0; i < 20; ++i)
+        for (int i = 0; i < BLOCKS; ++i)
             update(msg, sizeof(msg));
         final(md);
     }
@@ -51,7 +54,7 @@ int main(void)
     ts2.tv_sec -= ts1.tv_sec;
     ts2.tv_nsec -= ts1.tv_nsec;
     double took = ts2.tv_sec + (ts2.tv_nsec / 1000000000.0);
-    double speed = (((512 * 20) >> 10) * 100) / took;
+    double speed = ((SIZE * BLOCKS * ITER) / took) / (1 << 20);
     printf("took %.09f seconds, hashing %f MiB/s\n", took, speed);
 
     return 0;