From: Michael Vrable Date: Mon, 11 Jan 2010 22:50:10 +0000 (-0800) Subject: Quick tool for benchmarking write latency. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=1f827ab48a0bedc87a1019105429cb2578418829;p=bluesky.git Quick tool for benchmarking write latency. --- diff --git a/microbench/bench.c b/microbench/bench.c new file mode 100644 index 0000000..e0adab8 --- /dev/null +++ b/microbench/bench.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include + +int64_t now_hires() +{ + struct timespec time; + + if (clock_gettime(CLOCK_REALTIME, &time) != 0) { + perror("clock_gettime"); + return 0; + } + + return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec; +} + +void bench_write() +{ + FILE *f = fopen("writetest", "wb"); + if (f == NULL) { + perror("fopen"); + return; + } + + char buf[4096]; + for (int i = 0; i < 16; i++) { + int64_t start, end; + start = now_hires(); + rewind(f); + fwrite(buf, 1, sizeof(buf), f); + fflush(f); + end = now_hires(); + printf("Pass %d: Time = %"PRIi64"\n", i, end - start); + } +} + +int main(int argc, char *argv[]) +{ + bench_write(); +}