stew

a monorepo of some sort
git clone git://git.nsmpr.xyz/stew.git
Log | Files | Refs

ramstress.c (849B)


      1 /*
      2 	Create n files, then read n files in /tmp;
      3 	measure time.
      4 */
      5 
      6 #include <u.h>
      7 #include <libc.h>
      8 
      9 char buf[256];
     10 
     11 void
     12 create1(char *path)
     13 {
     14 	int n, fd = create(path, OWRITE, 0666);
     15 	if (fd < 0) sysfatal("%r");
     16 	n = snprint(buf, 256, "uhehe guhehe\n");
     17 	write(fd, buf, n);
     18 	close(fd);
     19 }
     20 
     21 void
     22 read1(char *path)
     23 {
     24 	int fd = open(path, OREAD);
     25 	if (fd < 0) sysfatal("%r");
     26 	read(fd, buf, 256);
     27 	close(fd);
     28 }
     29 
     30 void
     31 main(int argc, char **argv)
     32 {
     33 	long t[2], b[4];
     34 	if (argc < 2) exits("no arg");
     35 	long i, l = strtol(argv[1], nil, 10);
     36 	t[0] = times(b);
     37 	for (i = 0; i < l; i++) {
     38 		snprint(buf, 256, "/tmp/%ld", i);
     39 		create1(buf);
     40 	}
     41 	t[1] = times(b);
     42 	print("create: %ld ms\n", t[1] - t[0]);
     43 	t[0] = times(b);
     44 	for (i = 0; i < l; i++) {
     45 		snprint(buf, 256, "/tmp/%ld", i);
     46 		read1(buf);
     47 	}
     48 	t[1] = times(b);
     49 	print("read: %ld ms\n", t[1] - t[0]);
     50 }