It turns out this defect has nothing to do with file I/O at all.
The following code can reproduce the effect. I have raised a bug ticket with perlbug and the compiler of perl for cygwin.
## Test code to show split slow when used in muiltiple threads is slow + in cygwin perl use strict; use warnings; use threads; use Thread::Queue; use Time::HiRes(); my $string = "12356789 "x25; my $TASK_COUNT =10; print( (`$^X -v`)[1]); thread_process(1); thread_process(4); sub thread_process { my $parallel = shift; my $start = Time::HiRes::time(); my @threads; my $queue = Thread::Queue->new(); for my $p ( 1 .. $parallel ) { push @threads, threads->create( sub { while( my $task_no = $queue->dequeue) { for my $n (1..10_000) { my @x= split / /, $string; # Split } }}) } $queue->enqueue( 1 .. $TASK_COUNT , (undef) x $parallel ); $_->join for @threads; my $end= Time::HiRes::time(); printf "Processing %d tasks in %d threads completed in %fsecs\n", +$TASK_COUNT, $parallel, $end-$start; } __END__ # Here is an example of the output on my dual core XP machine $ ~/localperl/bin/perl.exe example.split.pl This is perl 5, version 14, subversion 1 (v5.14.1) built for cygwin-th +read-multi-64int Processing 10 tasks in 1 threads completed in 2.640625secs Processing 10 tasks in 4 threads completed in 12.468637secs $ perl example.split.pl This is perl, v5.10.0 built for cygwin-thread-multi-64int Processing 10 tasks in 1 threads completed in 4.578125secs Processing 10 tasks in 4 threads completed in 25.437345secs # The defect does not occur with ActivePerl. Instead the expected slig +htly faster result occurs $ c:/perl/bin/perl example.split.pl This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x +86-multi-thread Processing 10 tasks in 1 threads completed in 2.062500secs Processing 10 tasks in 4 threads completed in 1.671790secs
In reply to Re: Reading from file in threaded code is slow
by amcglinchy
in thread Reading from file in threaded code is slow
by amcglinchy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |