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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.