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"
22 #define NR_CHUNKS 2048U
43 static void randomize_buf(void *buf, unsigned int size, int seed)
45 struct frand_state state;
47 init_rand_seed(&state, seed);
48 fill_random_buf(&state, buf, size);
51 static uint64_t t_md5(void)
54 struct fio_md5_ctx ctx = { .hash = digest };
63 randomize_buf(buf, CHUNK, 0x8989);
65 fio_gettime(&s, NULL);
66 for (i = 0; i < NR_CHUNKS; i++)
67 fio_md5_update(&ctx, buf, CHUNK);
69 ret = utime_since_now(&s);
74 static uint64_t t_crc64(void)
82 randomize_buf(buf, CHUNK, 0x8989);
84 fio_gettime(&s, NULL);
85 for (i = 0; i < NR_CHUNKS; i++)
86 fio_crc64(buf, CHUNK);
88 ret = utime_since_now(&s);
93 static uint64_t t_crc32(void)
101 randomize_buf(buf, CHUNK, 0x8989);
103 fio_gettime(&s, NULL);
104 for (i = 0; i < NR_CHUNKS; i++)
105 fio_crc32(buf, CHUNK);
107 ret = utime_since_now(&s);
112 static uint64_t t_crc32c(void)
120 randomize_buf(buf, CHUNK, 0x8989);
122 fio_gettime(&s, NULL);
123 for (i = 0; i < NR_CHUNKS; i++)
124 fio_crc32c(buf, CHUNK);
126 ret = utime_since_now(&s);
131 static uint64_t t_crc16(void)
139 randomize_buf(buf, CHUNK, 0x8989);
141 fio_gettime(&s, NULL);
142 for (i = 0; i < NR_CHUNKS; i++)
143 fio_crc16(buf, CHUNK);
145 ret = utime_since_now(&s);
150 static uint64_t t_crc7(void)
158 randomize_buf(buf, CHUNK, 0x8989);
160 fio_gettime(&s, NULL);
161 for (i = 0; i < NR_CHUNKS; i++)
162 fio_crc7(buf, CHUNK);
164 ret = utime_since_now(&s);
169 static uint64_t t_sha1(void)
172 struct fio_sha1_ctx ctx = { .H = sha };
181 randomize_buf(buf, CHUNK, 0x8989);
183 fio_gettime(&s, NULL);
184 for (i = 0; i < NR_CHUNKS; i++)
185 fio_sha1_update(&ctx, buf, CHUNK);
187 ret = utime_since_now(&s);
192 static uint64_t t_sha256(void)
195 struct fio_sha256_ctx ctx = { .buf = sha };
201 fio_sha256_init(&ctx);
204 randomize_buf(buf, CHUNK, 0x8989);
206 fio_gettime(&s, NULL);
207 for (i = 0; i < NR_CHUNKS; i++)
208 fio_sha256_update(&ctx, buf, CHUNK);
210 ret = utime_since_now(&s);
215 static uint64_t t_sha512(void)
218 struct fio_sha512_ctx ctx = { .buf = sha };
224 fio_sha512_init(&ctx);
227 randomize_buf(buf, CHUNK, 0x8989);
229 fio_gettime(&s, NULL);
230 for (i = 0; i < NR_CHUNKS; i++)
231 fio_sha512_update(&ctx, buf, CHUNK);
233 ret = utime_since_now(&s);
238 static uint64_t t_xxhash(void)
246 state = XXH32_init(0x8989);
249 randomize_buf(buf, CHUNK, 0x8989);
251 fio_gettime(&s, NULL);
252 for (i = 0; i < NR_CHUNKS; i++)
253 XXH32_update(state, buf, CHUNK);
256 ret = utime_since_now(&s);
261 static struct test_type t[] = {
317 static unsigned int get_test_mask(const char *type)
319 char *ostr, *str = strdup(type);
326 while ((name = strsep(&str, ",")) != NULL) {
327 for (i = 0; t[i].name; i++) {
328 if (!strcmp(t[i].name, name)) {
339 static int list_types(void)
343 for (i = 0; t[i].name; i++)
344 printf("%s\n", t[i].name);
349 int fio_crctest(const char *type)
351 unsigned int test_mask = 0;
352 uint64_t mb = CHUNK * NR_CHUNKS;
355 crc32c_intel_probe();
359 else if (!strcmp(type, "help") || !strcmp(type, "list"))
362 test_mask = get_test_mask(type);
364 for (i = 0; t[i].name; i++) {
368 if (!(t[i].mask & test_mask))
372 mb_sec = (double) mb / (double) usec;
373 mb_sec /= (1.024 * 1.024);
374 printf("%s:\t%.2f MB/sec\n", t[i].name, mb_sec);