Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Created June 26, 2010 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dpavlin/454137 to your computer and use it in GitHub Desktop.
Save dpavlin/454137 to your computer and use it in GitHub Desktop.
use Benchmark qw(:all);
use Devel::Size;
use DevXX::Size;
use Storable;
sub _storable_freeze {
length Storable::freeze $_[0];
}
sub _storable_reopen {
open(my $fh, '|-', 'cat > /dev/null');
Storable::store_fd $_[0], $fh;
tell($fh);
}
open(my $fh, '|-', 'cat > /dev/null');
sub _storable_cat {
my $pos = tell($fh);
Storable::store_fd $_[0], $fh;
tell($fh) - $pos;
}
my $o;
$o->{$_} = rand() foreach ( 'a' .. 'z' );
my $hash;
my $nr = 0;
foreach ( 1 .. 10 ) {
$hash->{ $nr++ } = $o foreach ( 1 .. 10000 );
warn "# $nr elements\n";
cmpthese( int(1000 / $_), {
'size_0.71' => sub { Devel::Size::total_size( $hash ) },
'size_0.72' => sub { DevXX::Size::total_size( $hash ) },
'freeze' => sub { _storable_freeze( $hash ) },
'reopen' => sub { _storable_reopen( $hash ) },
'cat' => sub { _storable_cat( $hash ) },
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment