use 5.010; use Time::HiRes qw(time); my $data = 'x' x 500 * 1024**2; my $t = time; for my $n ( 1 .. 100 ) { unless (fork) { substr( $data, 4096 * $_ + $n, 1 ) |= 1 for 0 .. 124; exit; } } waitall; say time - $t; #### use strict; use warnings; use 5.010; use Time::HiRes qw(time); my $data = 'x' x 500 * 1024**2; my $t = time; for my $n ( 1 .. 100 ) { unless (fork) { substr( $data, 4096 * $_ + $n, 1 ) |= chr(1) for 0 .. 124; exit; } } waitall; say time - $t; #### #! perl -slw use strict; use 5.010; use threads ( stack_size => 4096 ); use Thread::Queue; use Time::HiRes qw(time); use constant DATA_SIZE => (500 * 1024**2); sub thread { my( $Q, $n ) = @_; $Q->enqueue( 4096 * $_ + $n ) for 0 .. 124; $Q->enqueue( undef ); } my $t = time; my $Q = new Thread::Queue; my @t = map threads->create( \&thread, $Q, $_ ), 1 .. 100; my $data = 'x' x DATA_SIZE ; for(1..100) { substr( $data, $_, 1 ) |= chr(1) while $_ = $Q->dequeue; } $_->join for @t; say time - $t; printf "%d bits changed\n", DATA_SIZE - ( $data =~ tr[x][] ); __END__ c:\test>junk44 2.03600001335144 12500 bits changed