in reply to Re^2: 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.

perhaps on Windows you will get other result.

On windows, those two pieces of code are all but identical (except the fork version leaks scalars). Hence, there is little difference between them. I'd be interested to see the results without the 32M scalar if you've a moment?

  • Comment on Re^3: while reading a file, transfer the same data to two different processes.

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

    Without 32M scalar it outputs:

    Rate Threads Forks Threads 230/s -- -0% Forks 231/s 0% --

      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)