in reply to Re^3: while reading a file, transfer the same data to two different processes.
in thread while reading a file, transfer the same data to two different processes.

Without 32M scalar it outputs:

Rate Threads Forks Threads 230/s -- -0% Forks 231/s 0% --
  • Comment on Re^4: while reading a file, transfer the same data to two different processes.
  • Download Code

Replies are listed 'Best First'.
Re^5: while reading a file, transfer the same data to two different processes.
by BrowserUk (Patriarch) on May 20, 2010 at 23:23 UTC

    Thanks. If you've the inclination to indulge me a little further, what results do you get from the following?

    use strict; use warnings; use threads; my $str = 'x' x 32_000_000; sub fork_wait { my $pid = fork; if ($pid) { wait; } else { my $l = length( $str ); exit 0; } } sub create_thread_join { threads->create( sub { my $l = length( $str ) } )->join; } use Benchmark qw( cmpthese ); cmpthese - 3, { Forks => \&fork_wait, Threads => \&create_thread_join, };
      Rate Threads Forks Threads 25.2/s -- -54% Forks 54.7/s 118% -- perl v5.10.1 built for x86_64-linux-thread-multi (Ubuntu 8.04) Rate Threads Forks Threads 21.5/s -- -72% Forks 77.6/s 261% -- perl v5.12.0 built for x86_64-linux-thread-multi (openSUSE 11.1)

        Interesting, thank you Almut.

        If you have time & inclination, I've one final line of enquiry:

        use strict; use warnings; use threads; my $str = 'x' x 32_000_000; sub fork_wait { my $pid = fork; if ($pid) { wait; } else { substr( $str, $_, 1 ) &= ~ ' ' for 0 .. length( $str ) -1; exit 0; } } sub create_thread_join { threads->create( sub { substr( $str, $_, 1 ) &= ~ ' ' for 0 .. length( $str ) -1; } )->join; } use Benchmark qw( cmpthese ); cmpthese - 3, { Forks => \&fork_wait, Threads => \&create_thread_join, };