$ alias tperl="time perl -w -Mthreads -Mthreads::shared" # No data to copy: $ tperl -e'threads->create(sub{})->join() for 1..100' $ tperl -e'threads->create(sub{})->join() for 1..100' CPU 0.680 secs (CPU 0.256 secs) # Load the data late so also no data is copied: $ tperl -e'BEGIN{threads->create(sub{})->join() for 1..100}my @x=(1..35_000)' CPU 0.728 secs (CPU 0.268 secs) $ tperl -e'BEGIN{threads->create(sub{})->join() for 1..100}my @x;share(@x);@x=(1..35_000)' CPU 0.840 secs (CPU 0.364 secs) # Overhead of copying, whether shared() or not: $ tperl -e'my @x;share(@x);@x=(1..35_000);threads->create(sub{})->join() for 1..100' CPU 2.272 secs (CPU 1.316 secs) $ tperl -e'my @x=(1..35_000);threads->create(sub{})->join() for 1..100' CPU 3.304 secs (CPU 3.384 secs) #### $ tperl -e'my @x=(1..35_000);threads->create(sub{for(@x){my$y=$_}})->join() for 1..100' CPU 4.324 secs $ tperl -e'my @x;share(@x);@x=(1..35_000);threads->create(sub{for(@x){my$y=$_}})->join() for 1..100' CPU 17.281 secs #### $ tperl -e'fork && exit for 1..100' CPU 0.044 secs (CPU 0.020 secs) $ tperl -e'my @x=(1..35_000);share(@x);fork && exit for 1..100' CPU 0.072 secs (CPU 0.072 secs) $ tperl -e'my @x=(1..35_000);for(1..100){if(fork){for(@x){my$y=$_};exit}}' CPU 0.084 secs #### # Try to load the data late but mostly fail: $ tperl -e'threads->create(sub{})->join() for 1..100;my @x=(1..35_000)' CPU 2.048 secs (CPU 1.204 secs) # Note how easy it is to do it wrong and not share data but get the overhead: $ tperl -e'my @x=(1..35_000);share(@x);print "($x[0])\n";threads->create(sub{})->join() for 1..100' Use of uninitialized value in concatenation (.) or string at -e line 1. () CPU 3.380 secs (CPU 2.128 secs)