#! perl -slw use strict; use threads; use threads::shared; use Thread::Queue; use Storable qw[ freeze thaw ]; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 2000; our $N //= 1000; our $H //= 100; { my $start = Win32::GetTickCount(); my $Q = new Thread::Queue; async{ my %h = 1 .. $H; $Q->enqueue( \%h ) for 1 .. $N; $Q->enqueue( undef ); }->detach; my %h; %h = %{ $_ } while defined( $_ = $Q->dequeue ); printf "Unshared hashrefs: %.3f\n", ( Win32::GetTickCount() - $start ) / 1000; } { my $start = Win32::GetTickCount(); my $Q = new Thread::Queue; async{ my %h = 1 .. $H; $Q->enqueue( join $;, %h ) for 1 .. $N; $Q->enqueue( undef ); }->detach; my %h; %h = split $;, $_ while defined( $_ = $Q->dequeue ); printf "join/split: %.3f\n", ( Win32::GetTickCount() - $start ) / 1000; } { my $start = Win32::GetTickCount(); my $Q = new Thread::Queue; async{ my %h = 1 .. $H; $Q->enqueue( freeze \%h ) for 1 .. $N; $Q->enqueue( undef ); }->detach; my $href; $href = thaw $_ while defined( $_ = $Q->dequeue ); printf "freeze/thaw: %.3f\n", ( Win32::GetTickCount() - $start ) / 1000; } { my $start = Win32::GetTickCount(); my $Q = new Thread::Queue; async{ my %h :shared = 1 .. $H; $Q->enqueue( \%h ) for 1 .. $N; $Q->enqueue( undef ); }->detach; my $href; 1 while defined( $href = $Q->dequeue ); printf "Shared hashrefs: %.3f\n", ( Win32::GetTickCount() - $start ) / 1000; }