Bothe timethese & compthese show poor performance for after..#!/usr/bin/perl use threads; use Benchmark qw(:all) ; my $line_var :shared = 0; sub main_func { my ($tid, $in_fh , $out_fh, $start , $stop) = @_; # Synchronised block ++$line_var; while (<$in_fh>) { print $out_fh " LineVar.. $line_var\t" . $_ ; } return $tid; } sub super_main { open (OUTFH1 , "< out1.txt"); open (OUTFH2 , "< out2.txt"); open (OUTFH3 , "< out3.txt"); open (OUTFH4 , "< out4.txt"); open (OUTFHO1 , "> outO1.txt"); open (OUTFHO2 , "> outO2.txt"); open (OUTFHO3 , "> outO3.txt"); open (OUTFHO4 , "> outO4.txt"); $thr1 = threads->create(\&main_func , '1', OUTFH1,OUTFHO1, '1' , ' +1000000'); $thr2 = threads->create(\&main_func , '2', OUTFH2,OUTFHO2, '100000 +0' , '2000000'); $thr3 = threads->create(\&main_func , '3', OUTFH3,OUTFHO3,'2000000 +' , '3000000'); $thr4 = threads->create(\&main_func , '4', OUTFH4,OUTFHO4,'3000000 +' , '4000000'); $tid1 = $thr1->join(); $tid2 = $thr2->join(); $tid3 = $thr3->join(); $tid4 = $thr4->join(); } sub main_func2 { my $line_var2 = 0; open (OUTFHO5 , "> outO5.txt"); my ($tid, $out_fh ,$start , $stop) = (5,OUTFHO5,'1' , '4000000'); for ($i = 1 ; $i<5; $i++) { open (INFH , "< out$i.txt"); while (<INFH>) { $line_var2++; print $out_fh " Line.. $line_var2\t" . $_ ; } } return $tid; } #timethese ( 20, # {'before' => \&main_func2 , # 'after' => \&super_main } # ); cmpthese ( 20, {'before' => \&main_func2 , 'after' => \&super_main } );
So the question is... Have I made a mistake in the program... OR is threading not tht beneficial ??---------- Perl ---------- s/iter after before after 10.9 -- -18% before 8.99 22% -- Output completed (12 min 45 sec consumed) - Normal Termination
In reply to Threads Doubt by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |