in reply to Re: 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.
Well, every thread has some overhead too:
use strict; use warnings; use threads; my $str = 'x' x 32_000_000; sub fork_wait { my $pid = fork; if ($pid) { wait; } else { exit 0; } } sub create_thread_join { threads->create( sub { } )->join; } use Benchmark qw( cmpthese ); cmpthese - 3, { Forks => \&fork_wait, Threads => \&create_thread_join, }; __END__ Rate Threads Forks Threads 27.7/s -- -73% Forks 103/s 272% --
Even without this 32M string threads not win. This is Linux, perhaps on Windows you will get other result.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: while reading a file, transfer the same data to two different processes.
by BrowserUk (Patriarch) on May 20, 2010 at 20:27 UTC | |
by zwon (Abbot) on May 20, 2010 at 20:47 UTC | |
by BrowserUk (Patriarch) on May 20, 2010 at 23:23 UTC | |
by almut (Canon) on May 20, 2010 at 23:57 UTC | |
by BrowserUk (Patriarch) on May 21, 2010 at 00:29 UTC | |
|