summaryrefslogtreecommitdiff
path: root/crc
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-07-25 10:12:26 +0200
committerJens Axboe <axboe@fb.com>2014-07-25 10:12:26 +0200
commit24ef7a61bc7b9ec0f479980b6b219ef7d986d708 (patch)
tree5c010bc059808b51eab844ec2e7ba3db5c2091e4 /crc
parent69bdd6badc47775443413405e1aea4abe9e570c9 (diff)
downloadfio-24ef7a61bc7b9ec0f479980b6b219ef7d986d708.tar.gz
fio-24ef7a61bc7b9ec0f479980b6b219ef7d986d708.tar.bz2
crc/test: cleanup and better precision
Make sure we're a bit cache warm at least, and don't allocate, free, and randomize a buffer for each hash. Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'crc')
-rw-r--r--crc/test.c132
1 files changed, 43 insertions, 89 deletions
diff --git a/crc/test.c b/crc/test.c
index 3ce717a0..194bbed9 100644
--- a/crc/test.c
+++ b/crc/test.c
@@ -26,7 +26,7 @@
struct test_type {
const char *name;
unsigned int mask;
- uint64_t (*fn)(void);
+ uint64_t (*fn)(void *, size_t);
};
enum {
@@ -50,213 +50,153 @@ static void randomize_buf(void *buf, unsigned int size, int seed)
fill_random_buf(&state, buf, size);
}
-static uint64_t t_md5(void)
+static uint64_t t_md5(void *buf, size_t size)
{
uint32_t digest[4];
struct fio_md5_ctx ctx = { .hash = digest };
struct timeval s;
- uint64_t ret;
- void *buf;
int i;
fio_md5_init(&ctx);
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_md5_update(&ctx, buf, CHUNK);
+ fio_md5_update(&ctx, buf, size);
- ret = utime_since_now(&s);
- free(buf);
- return ret;
+ return utime_since_now(&s);
}
-static uint64_t t_crc64(void)
+static uint64_t t_crc64(void *buf, size_t size)
{
struct timeval s;
- uint64_t ret;
- void *buf;
int i;
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_crc64(buf, CHUNK);
+ fio_crc64(buf, size);
- ret = utime_since_now(&s);
- free(buf);
- return ret;
+ return utime_since_now(&s);
}
-static uint64_t t_crc32(void)
+static uint64_t t_crc32(void *buf, size_t size)
{
struct timeval s;
- uint64_t ret;
- void *buf;
int i;
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_crc32(buf, CHUNK);
+ fio_crc32(buf, size);
- ret = utime_since_now(&s);
- free(buf);
- return ret;
+ return utime_since_now(&s);
}
-static uint64_t t_crc32c(void)
+static uint64_t t_crc32c(void *buf, size_t size)
{
struct timeval s;
- uint64_t ret;
- void *buf;
int i;
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_crc32c(buf, CHUNK);
+ fio_crc32c(buf, size);
- ret = utime_since_now(&s);
- free(buf);
- return ret;
+ return utime_since_now(&s);
}
-static uint64_t t_crc16(void)
+static uint64_t t_crc16(void *buf, size_t size)
{
struct timeval s;
- uint64_t ret;
- void *buf;
int i;
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_crc16(buf, CHUNK);
+ fio_crc16(buf, size);
- ret = utime_since_now(&s);
- free(buf);
- return ret;
+ return utime_since_now(&s);
}
-static uint64_t t_crc7(void)
+static uint64_t t_crc7(void *buf, size_t size)
{
struct timeval s;
uint64_t ret;
- void *buf;
int i;
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_crc7(buf, CHUNK);
+ fio_crc7(buf, size);
ret = utime_since_now(&s);
- free(buf);
return ret;
}
-static uint64_t t_sha1(void)
+static uint64_t t_sha1(void *buf, size_t size)
{
uint32_t sha[5];
struct fio_sha1_ctx ctx = { .H = sha };
struct timeval s;
uint64_t ret;
- void *buf;
int i;
fio_sha1_init(&ctx);
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_sha1_update(&ctx, buf, CHUNK);
+ fio_sha1_update(&ctx, buf, size);
ret = utime_since_now(&s);
- free(buf);
return ret;
}
-static uint64_t t_sha256(void)
+static uint64_t t_sha256(void *buf, size_t size)
{
uint8_t sha[64];
struct fio_sha256_ctx ctx = { .buf = sha };
struct timeval s;
uint64_t ret;
- void *buf;
int i;
fio_sha256_init(&ctx);
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_sha256_update(&ctx, buf, CHUNK);
+ fio_sha256_update(&ctx, buf, size);
ret = utime_since_now(&s);
- free(buf);
return ret;
}
-static uint64_t t_sha512(void)
+static uint64_t t_sha512(void *buf, size_t size)
{
uint8_t sha[128];
struct fio_sha512_ctx ctx = { .buf = sha };
struct timeval s;
uint64_t ret;
- void *buf;
int i;
fio_sha512_init(&ctx);
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- fio_sha512_update(&ctx, buf, CHUNK);
+ fio_sha512_update(&ctx, buf, size);
ret = utime_since_now(&s);
- free(buf);
return ret;
}
-static uint64_t t_xxhash(void)
+static uint64_t t_xxhash(void *buf, size_t size)
{
void *state;
struct timeval s;
uint64_t ret;
- void *buf;
int i;
state = XXH32_init(0x8989);
- buf = malloc(CHUNK);
- randomize_buf(buf, CHUNK, 0x8989);
-
fio_gettime(&s, NULL);
for (i = 0; i < NR_CHUNKS; i++)
- XXH32_update(state, buf, CHUNK);
+ XXH32_update(state, buf, size);
XXH32_digest(state);
ret = utime_since_now(&s);
- free(buf);
return ret;
}
@@ -345,14 +285,15 @@ static int list_types(void)
for (i = 0; t[i].name; i++)
printf("%s\n", t[i].name);
- return 0;
+ return 1;
}
int fio_crctest(const char *type)
{
unsigned int test_mask = 0;
uint64_t mb = CHUNK * NR_CHUNKS;
- int i;
+ int i, first = 1;
+ void *buf;
crc32c_intel_probe();
@@ -363,6 +304,14 @@ int fio_crctest(const char *type)
else
test_mask = get_test_mask(type);
+ if (!test_mask) {
+ fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
+ return list_types();
+ }
+
+ buf = malloc(CHUNK);
+ randomize_buf(buf, CHUNK, 0x8989);
+
for (i = 0; t[i].name; i++) {
double mb_sec;
uint64_t usec;
@@ -370,11 +319,16 @@ int fio_crctest(const char *type)
if (!(t[i].mask & test_mask))
continue;
- usec = t[i].fn();
+ usec = t[i].fn(buf, CHUNK);
+ if (first)
+ usec = t[i].fn(buf, CHUNK);
+
mb_sec = (double) mb / (double) usec;
mb_sec /= (1.024 * 1.024);
printf("%s:\t%8.2f MB/sec\n", t[i].name, mb_sec);
+ first = 0;
}
+ free(buf);
return 0;
}