From: "Linux Portal" <linportal@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: Simple utility to measure disk random access time
Date: Tue, 16 Jan 2007 15:49:45 +0100 [thread overview]
Message-ID: <ceccffee0701160649w5e401cf9i433f61beeb26e2b1@mail.gmail.com> (raw)
And a few graphs here: http://linux.inet.hr/how_fast_is_your_disk.html
Comments welcome!
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#define BLOCKSIZE 512
#define TIMEOUT 30
int count;
time_t start;
void done()
{
time_t end;
time(&end);
if (end < start + TIMEOUT) {
printf(".");
alarm(1);
return;
}
if (count) {
printf(".\nResults: %d seeks/second, %.2f ms random access time\n",
count / TIMEOUT, 1000.0 * TIMEOUT / count);
}
exit(EXIT_SUCCESS);
}
void handle(const char *string, int error)
{
if (error) {
perror(string);
exit(EXIT_FAILURE);
}
}
int main(int argc, char **argv)
{
char buffer[BLOCKSIZE];
int fd, retval;
unsigned long numblocks;
off64_t offset;
setvbuf(stdout, NULL, _IONBF, 0);
printf("Seeker v2.0, 2007-01-15, "
"http://linux.inet.hr/how_fast_is_your_disk.html\n");
if (argc != 2) {
printf("Usage: seeker <raw disk device>\n");
exit(EXIT_SUCCESS);
}
fd = open(argv[1], O_RDONLY);
handle("open", fd < 0);
retval = ioctl(fd, BLKGETSIZE, &numblocks);
handle("ioctl", retval == -1);
printf("Benchmarking %s [%luMB], wait %d seconds",
argv[1], numblocks / 2048, TIMEOUT);
time(&start);
srand(start);
signal(SIGALRM, &done);
alarm(1);
for (;;) {
offset = (off64_t) numblocks * random() / RAND_MAX;
retval = lseek64(fd, BLOCKSIZE * offset, SEEK_SET);
handle("lseek64", retval == (off64_t) -1);
retval = read(fd, buffer, BLOCKSIZE);
handle("read", retval < 0);
count++;
}
/* notreached */
}
next reply other threads:[~2007-01-16 14:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-16 14:49 Linux Portal [this message]
2007-01-16 19:01 ` Bill Davidsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ceccffee0701160649w5e401cf9i433f61beeb26e2b1@mail.gmail.com \
--to=linportal@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®