6 #include "../gettime.h"
10 #include "../crc/md5.h"
11 #include "../crc/crc64.h"
12 #include "../crc/crc32.h"
13 #include "../crc/crc32c.h"
14 #include "../crc/crc16.h"
15 #include "../crc/crc7.h"
16 #include "../crc/sha1.h"
17 #include "../crc/sha256.h"
18 #include "../crc/sha512.h"
19 #include "../crc/xxhash.h"
24 #define NR_CHUNKS 2048U
45 static void randomize_buf(void *buf, unsigned int size, int seed)
47 struct frand_state state;
49 init_rand_seed(&state, seed);
50 fill_random_buf(&state, buf, size);
53 static uint64_t t_md5(void)
56 struct fio_md5_ctx ctx = { .hash = digest };
65 randomize_buf(buf, CHUNK, 0x8989);
67 fio_gettime(&s, NULL);
68 for (i = 0; i < NR_CHUNKS; i++)
69 fio_md5_update(&ctx, buf, CHUNK);
71 ret = utime_since_now(&s);
76 static uint64_t t_crc64(void)
84 randomize_buf(buf, CHUNK, 0x8989);
86 fio_gettime(&s, NULL);
87 for (i = 0; i < NR_CHUNKS; i++)
88 fio_crc64(buf, CHUNK);
90 ret = utime_since_now(&s);
95 static uint64_t t_crc32(void)
103 randomize_buf(buf, CHUNK, 0x8989);
105 fio_gettime(&s, NULL);
106 for (i = 0; i < NR_CHUNKS; i++)
107 fio_crc32(buf, CHUNK);
109 ret = utime_since_now(&s);
114 static uint64_t t_crc32c(void)
122 randomize_buf(buf, CHUNK, 0x8989);
124 fio_gettime(&s, NULL);
125 for (i = 0; i < NR_CHUNKS; i++)
126 fio_crc32c(buf, CHUNK);
128 ret = utime_since_now(&s);
133 static uint64_t t_crc16(void)
141 randomize_buf(buf, CHUNK, 0x8989);
143 fio_gettime(&s, NULL);
144 for (i = 0; i < NR_CHUNKS; i++)
145 fio_crc16(buf, CHUNK);
147 ret = utime_since_now(&s);
152 static uint64_t t_crc7(void)
160 randomize_buf(buf, CHUNK, 0x8989);
162 fio_gettime(&s, NULL);
163 for (i = 0; i < NR_CHUNKS; i++)
164 fio_crc7(buf, CHUNK);
166 ret = utime_since_now(&s);
171 static uint64_t t_sha1(void)
174 struct fio_sha1_ctx ctx = { .H = sha };
183 randomize_buf(buf, CHUNK, 0x8989);
185 fio_gettime(&s, NULL);
186 for (i = 0; i < NR_CHUNKS; i++)
187 fio_sha1_update(&ctx, buf, CHUNK);
189 ret = utime_since_now(&s);
194 static uint64_t t_sha256(void)
197 struct fio_sha256_ctx ctx = { .buf = sha };
203 fio_sha256_init(&ctx);
206 randomize_buf(buf, CHUNK, 0x8989);
208 fio_gettime(&s, NULL);
209 for (i = 0; i < NR_CHUNKS; i++)
210 fio_sha256_update(&ctx, buf, CHUNK);
212 ret = utime_since_now(&s);
217 static uint64_t t_sha512(void)
220 struct fio_sha512_ctx ctx = { .buf = sha };
226 fio_sha512_init(&ctx);
229 randomize_buf(buf, CHUNK, 0x8989);
231 fio_gettime(&s, NULL);
232 for (i = 0; i < NR_CHUNKS; i++)
233 fio_sha512_update(&ctx, buf, CHUNK);
235 ret = utime_since_now(&s);
240 static uint64_t t_xxhash(void)
248 state = XXH32_init(0x8989);
251 randomize_buf(buf, CHUNK, 0x8989);
253 fio_gettime(&s, NULL);
254 for (i = 0; i < NR_CHUNKS; i++)
255 XXH32_update(state, buf, CHUNK);
258 ret = utime_since_now(&s);
263 static struct test_type t[] = {
319 static unsigned int get_test_mask(const char *type)
321 char *ostr, *str = strdup(type);
328 while ((name = strsep(&str, ",")) != NULL) {
329 for (i = 0; t[i].name; i++) {
330 if (!strcmp(t[i].name, name)) {
341 static int list_types(void)
345 for (i = 0; t[i].name; i++)
346 printf("%s\n", t[i].name);
351 int fio_crctest(const char *type)
353 unsigned int test_mask = 0;
354 uint64_t mb = CHUNK * NR_CHUNKS;
357 crc32c_intel_probe();
361 else if (!strcmp(type, "help") || !strcmp(type, "list"))
364 test_mask = get_test_mask(type);
366 for (i = 0; t[i].name; i++) {
370 if (!(t[i].mask & test_mask))
374 mb_sec = (double) mb / (double) usec;
375 mb_sec /= (1.024 * 1.024);
376 printf("%s:\t%.2f MB/sec\n", t[i].name, mb_sec);