Created
November 3, 2011 09:11
-
-
Save KristianLyng/1336100 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
| root@luke:~/tmpfs# cat foo.sh | |
| rfile=$(mktemp) | |
| size=$1 | |
| gcc -x c -O3 -o $rfile - <<__EOF__ | |
| #include <stdlib.h> | |
| int main(void) { | |
| int i; | |
| long int a; | |
| char *b; | |
| char buff[100010]; | |
| int buflen=0; | |
| int intcounter; | |
| srandom(time(NULL)); | |
| b = (char *) &a; | |
| for (i=0;i < ($1 / sizeof(long int));i++) { | |
| a = random(); | |
| for (intcounter=0; intcounter<sizeof(long int); intcounter++) | |
| buff[buflen+intcounter] = b[intcounter]; | |
| buflen+=intcounter; | |
| if (buflen > 100000){ | |
| write(1,buff,buflen); | |
| buflen=0; | |
| } | |
| } | |
| write(1,buff,buflen); | |
| return 0; | |
| } | |
| __EOF__ | |
| $rfile > tmpfile; ls -lh tmpfile | |
| rm $rfile | |
| root@luke:~/tmpfs# time ./foo.sh 40000000 | |
| -rw-r--r-- 1 root root 39M Nov 3 10:10 tmpfile | |
| real 0m0.144s | |
| user 0m0.116s | |
| sys 0m0.032s | |
| root@luke:~/tmpfs# |
Author
Why not just do:
dd if=/dev/random of=tmpfile bs=1000 count=4000
or /dev/urandom if you're on a machine without a lot of entropy.
I do like the evilness, but, seems like a lot of overkill. :)
Author
Because urandom is ridiculously slow. On my rather fast system /dev/urandom (Which is the FAST one) pulls 7.5MB/s.
Author
Oh, it's also obviously mostly a joke now. A far better solution is just using shred, which gives comparable speeds. But I still like the vileness :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or for something bigger?
root@luke:~/tmpfs# time ./foo.sh 4000000000
-rw-r--r-- 1 root root 3.8G Nov 3 10:13 tmpfile
real 0m8.097s
user 0m6.828s
sys 0m1.280s