in reply to Count byte/character occurrence (quickly)
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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Count byte/character occurrence (1/4)
by hippo (Archbishop) on Apr 01, 2016 at 10:46 UTC | |
by BrowserUk (Patriarch) on Apr 01, 2016 at 11:12 UTC | |
by hippo (Archbishop) on Apr 01, 2016 at 11:36 UTC | |
Re^2: Count byte/character occurrence (1/4)
by james28909 (Deacon) on Apr 01, 2016 at 15:58 UTC | |
Re^2: Count byte/character occurrence (1/4)
by james28909 (Deacon) on Apr 04, 2016 at 20:58 UTC | |
by BrowserUk (Patriarch) on Apr 04, 2016 at 21:05 UTC |