rand: add 64-bit tausworthe variant with a 2^258 cycle
[fio.git] / crc / test.c
index b2708a84e8c2c6b73446c6d3f13b420e14e145dd..05ea73e69e1abee7d15e7a17ec0cd75da7cd01b8 100644 (file)
@@ -17,7 +17,8 @@
 #include "../crc/sha256.h"
 #include "../crc/sha512.h"
 #include "../crc/xxhash.h"
-#include "../lib/murmur3.h"
+#include "../crc/murmur3.h"
+#include "../crc/fnv.h"
 #include "../hash.h"
 
 #include "test.h"
@@ -45,6 +46,7 @@ enum {
        T_XXHASH        = 1U << 9,
        T_MURMUR3       = 1U << 10,
        T_JHASH         = 1U << 11,
+       T_FNV           = 1U << 12,
 };
 
 static void t_md5(struct test_type *t, void *buf, size_t size)
@@ -55,10 +57,10 @@ static void t_md5(struct test_type *t, void *buf, size_t size)
 
        fio_md5_init(&ctx);
 
-       for (i = 0; i < NR_CHUNKS; i++)
+       for (i = 0; i < NR_CHUNKS; i++) {
                fio_md5_update(&ctx, buf, size);
-
-       fio_md5_final(&ctx);
+               fio_md5_final(&ctx);
+       }
 }
 
 static void t_crc64(struct test_type *t, void *buf, size_t size)
@@ -109,8 +111,10 @@ static void t_sha1(struct test_type *t, void *buf, size_t size)
 
        fio_sha1_init(&ctx);
 
-       for (i = 0; i < NR_CHUNKS; i++)
+       for (i = 0; i < NR_CHUNKS; i++) {
                fio_sha1_update(&ctx, buf, size);
+               fio_sha1_final(&ctx);
+       }
 }
 
 static void t_sha256(struct test_type *t, void *buf, size_t size)
@@ -121,10 +125,10 @@ static void t_sha256(struct test_type *t, void *buf, size_t size)
 
        fio_sha256_init(&ctx);
 
-       for (i = 0; i < NR_CHUNKS; i++)
+       for (i = 0; i < NR_CHUNKS; i++) {
                fio_sha256_update(&ctx, buf, size);
-
-       fio_sha256_final(&ctx);
+               fio_sha256_final(&ctx);
+       }
 }
 
 static void t_sha512(struct test_type *t, void *buf, size_t size)
@@ -155,6 +159,14 @@ static void t_jhash(struct test_type *t, void *buf, size_t size)
                t->output += jhash(buf, size, 0x8989);
 }
 
+static void t_fnv(struct test_type *t, void *buf, size_t size)
+{
+       int i;
+
+       for (i = 0; i < NR_CHUNKS; i++)
+               t->output += fnv(buf, size, 0x8989);
+}
+
 static void t_xxhash(struct test_type *t, void *buf, size_t size)
 {
        void *state;
@@ -229,6 +241,11 @@ static struct test_type t[] = {
                .mask = T_JHASH,
                .fn = t_jhash,
        },
+       {
+               .name = "fnv",
+               .mask = T_FNV,
+               .fn = t_fnv,
+       },
        {
                .name = NULL,
        },
@@ -289,7 +306,7 @@ int fio_crctest(const char *type)
        }
 
        buf = malloc(CHUNK);
-       init_rand_seed(&state, 0x8989);
+       init_rand_seed(&state, 0x8989, 0);
        fill_random_buf(&state, buf, CHUNK);
 
        for (i = 0; t[i].name; i++) {
@@ -314,13 +331,16 @@ int fio_crctest(const char *type)
                t[i].fn(&t[i], buf, CHUNK);
                usec = utime_since_now(&tv);
 
-               mb_sec = (double) mb / (double) usec;
-               mb_sec /= (1.024 * 1.024);
-               if (strlen(t[i].name) >= 7)
-                       sprintf(pre, "\t");
-               else
-                       sprintf(pre, "\t\t");
-               printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);
+               if (usec) {
+                       mb_sec = (double) mb / (double) usec;
+                       mb_sec /= (1.024 * 1.024);
+                       if (strlen(t[i].name) >= 7)
+                               sprintf(pre, "\t");
+                       else
+                               sprintf(pre, "\t\t");
+                       printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);
+               } else
+                       printf("%s:inf MB/sec\n", t[i].name);
                first = 0;
        }