While your version took 12 seconds for 16MB on my system:
C:\test>dir 1123355.bin 14/04/2015 16:50 16,777,216 1123355.bin C:\test>1159245 1123355.bin Took 12.897612 secs
(That was the third run so the cache was primed.)
This version took:
C:\test>1159245 1123355.bin Took 3.832763 secs : 3762666 ☺ : 46120 ☻ : 43642 ♥ : 44106 ♦ : 43878 ...
The code;
#! perl -slw use strict; use Time::HiRes qw[ time ]; my $start = time; open I, '<:raw', $ARGV[ 0 ]; my @seen; while( read( I, my $buf, 16384 ) ) { ++$seen[$_] for unpack 'C*', $buf; } printf "Took %f secs\n", time() - $start; printf "%c : %u\n", $_, $seen[$_] for 0 .. 255;
In reply to Re: Count byte/character occurrence (1/4)
by BrowserUk
in thread Count byte/character occurrence (quickly)
by james28909
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |