4 * cc seekbench.c -o /tmp/sb
6 * This intentionally performs a sequence of seek/reads with ever
7 * growing distances in a way that should be essentially uncached.
8 * It attempts to defeat both OS caches and the HDs zone cache.
10 * The average read-latency per seek/read is calculated.
12 * This can heat up the hard drive so be careful.
15 #include <sys/types.h>
24 #define BLKSIZE ((intmax_t)1024)
25 #define BLKMASK (BLKSIZE - 1)
30 main(int ac, char **av)
42 fprintf(stderr, "seekbench <blockdevice>\n");
45 fd = open(av[1], O_RDONLY);
51 bytes = lseek(fd, 0L, 1);
52 printf("%s: %jdMB\n", av[1], (intmax_t)bytes / 1024 / 1024);
53 printf("distance avg-seek\n");
55 while (skip < bytes) {
57 gettimeofday(&tv1, NULL);
58 for (base = skip; base < bytes && count < 100; base += skip) {
60 read(fd, Buf, BLKSIZE);
63 gettimeofday(&tv2, NULL);
64 us = (tv2.tv_usec + 1000000 - tv1.tv_usec) +
65 (tv2.tv_sec - 1 - tv1.tv_sec) * 1000000;
66 if (skip < 100*1024*1024)
67 printf("%5jdKB %6.3fms\n",
68 (intmax_t)skip / 1024,
69 (double)us / 1000.0 / count);
71 printf("%5jdMB %6.3fms\n",
72 (intmax_t)skip / 1024 / 1024,
73 (double)us / 1000.0 / count);
75 if (skip < BLKSIZE * 25)
78 skip += (skip / 25 + BLKMASK) & ~BLKMASK;