-
-
Save dw/3d89d9427ff10e29c456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create 1 million files, final directory size ~4.1gb: | |
// for i in {1..1024} ; do mkdir -p junk/$i ; for j in {1..1024} ; do cp /etc/hostname junk/$i/$j ; done; done | |
/* | |
[20:23:18 k2!58 ~] gcc -O2 -oa a.c | |
[20:23:19 k2!59 ~] time ./a | |
real 0m13.000s | |
*/ | |
#include <sys/types.h> | |
#include <assert.h> | |
#include <sys/uio.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
char rbuf[1048576]; | |
char ri, rj; | |
int rnd(void) | |
{ | |
if(++ri > sizeof rbuf) { | |
ri = 0; | |
} | |
return rbuf[ri] & ((1 << 10) - 1); | |
} | |
int main(void) | |
{ | |
char buffer[4096]; | |
char path[256]; | |
unsigned long i = 9999999; | |
int n; | |
int randfd = open("/dev/urandom", O_RDONLY); | |
assert(sizeof rbuf == read(randfd, rbuf, sizeof rbuf)); | |
while(i--) { | |
sprintf(path, "junk/%d/%d", 1+rnd(), 1+rnd()); | |
int fd = open(path, O_RDONLY); | |
if(fd == -1) { | |
perror(path); | |
return -1; | |
} | |
n = pread(fd, buffer, 1, 0); | |
close(fd); | |
} | |
printf("%d\n", (int)n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment