in reply to Is rand() really that slow or am I just using it wrong?
Most of your time is being spent building an 8-char string from 8 random bytes, then copying that to a 16-byte string and adding 8 more random bytes; then copying that to a 32-byte string and adding 16 more random bytes; then copying that to a 64-byte string ...
Try this version:
#! perl -slw use strict; my @chars = ('a'..'z', 'A'..'Z',0..9, qw[- _ ! & ? = ] ); sub genFile { my( $fh, $mb ) = @_; my $buf = chr(0) x 1024**2; for( 1 .. $mb ) { substr $buf, $_, 1, $chars[ rand @chars ] for 0 .. 1024**2-1; print $fh $buf; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is rand() really that slow or am I just using it wrong?
by adiuva (Sexton) on Aug 08, 2013 at 18:56 UTC | |
by BrowserUk (Patriarch) on Aug 08, 2013 at 21:51 UTC | |
by Anonymous Monk on Aug 09, 2013 at 14:06 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2013 at 14:46 UTC |