in reply to Re^4: Perl Hashes in C?
in thread Perl Hashes in C?

FWIW, this constructs a 216 MB file of random bytes in memory; then indexes it is 6-byte chunks to find 28 million "colors" in 37 million pixels in 56 seconds (and I'm guessing your machine is a lot faster than mine):

#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => '_1138218', CLEAN_AFTER_BUILD =>0; typedef unsigned __int64 U64; typedef unsigned int U32; typedef unsigned char U8; #define TAG printf( "%s[%u]\n", __FILE__, __LINE__ ) HV* countColors( SV *img ) { STRLEN l; U8 *p = SvPVx( img, l ); HV* counts = newHV(); U32 i; for( i = 0; i < l; i += 6 ) { SV **val; if( val = hv_fetch( counts, p+i, 6, 0 ) ) { ++SvUVX( *val ); } else { hv_store( counts, p+i, 6, newSVuv( 1 ), 0 ); } } return counts; } END_C use List::Util qw[ shuffle sum ]; my $data = ''; my @bytes = map chr, 0 .. 255; { local $/; open O, '>', \$data; seek O, 226492416, 0; print O chr(26 ); seek O, 0, 0; print O join '', ( shuffle( @bytes ) ) x 4 for 1 .. 221184; close O; } print length $data; my $start = time; my $href = countColors( $data ); printf "Took %f seconds\n", time() -$start; printf "Found %u colors in %u pixels\n", scalar( keys %{ $href } ), su +m( values %{ $href } ); __END__ C:\test>1138218-2 226713600 Took 56.000000 seconds Found 28532475 colors in 37785600 pixels

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!