#! perl -slw use Cwd; use Config; use Data::Dumper; use threads; use Benchmark qw(:all); use strict; use warnings; # Change this structure accordingly... my %allScripts = ( submitters => { numRuns => 4, steps => [ q[perl -wle"sleep int rand 3; print 'step1'"], q[perl -wle"sleep int rand 3; print 'step2'"] ] }, reviewers => { numRuns => 1, steps => [ q[perl -wle"sleep int rand 3; print 'step1'"], q[perl -wle"sleep int rand 3; print 'step2'"] ] } ); my $numCompleteTestRuns = 4; my $mscriptInterpreter = "ScriptRunner.exe"; my $currentDir = getcwd(); eval{ timethis( $numCompleteTestRuns, 'runTests' ) }; warn $@ if $@; sub runTests { print "Waiting to spawn processes."; foreach my $userType ( sort{ $allScripts{$a} <=> $allScripts{$b} } keys %allScripts ) { print "The $userType will run $allScripts{$userType}{numRuns} times. The steps are:"; foreach my $i (0 .. $#{ $allScripts{$userType}{steps}}) { print "$i = $allScripts{$userType}{steps}[$i]"; } } my @threadList = (); foreach my $userType ( sort {$allScripts{$a} <=> $allScripts{$b}} keys %allScripts ) { for my $i (0 .. $allScripts{$userType}{numRuns}) { print "About to create $userType thread $i:"; my $thread = threads->new(\&stepThread, \$allScripts{$userType}); push (@threadList, $thread); } } my $numThreads = @threadList; print "There are $numThreads threads"; # wait for each running thread to end foreach my $thread (@threadList) { $thread->join; print "A thread joined"; } print "Processes ended - Goodbye"; } # thread runs a type of users steps once only sub stepThread { print "starting thread"; my $currentUsertype = shift; foreach my $i ( 0 .. $#{ ${$currentUsertype}->{steps} } ) { my $fileName = ${ $currentUsertype }->{steps}[$i]; my $command = $fileName; print( "About to run: $fileName" ); my $time0 = new Benchmark; my $output = `$command`; my $time1 = new Benchmark; my $timeTaken = timestr( timediff( $time1, $time0 ) ); print "BEGIN $fileName\n'$output'\nEND $fileName output (time taken: $timeTaken)"; } print( "Ending thread" ); } #### Waiting to spawn processes. The submitters will run 4 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" The reviewers will run 1 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" About to create submitters thread 0: About to create submitters thread 1: About to create submitters thread 2: About to create submitters thread 3: About to create submitters thread 4: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" About to create reviewers thread 0: About to create reviewers thread 1: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread There are 7 threads A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined Processes ended - Goodbye Waiting to spawn processes. The submitters will run 4 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" The reviewers will run 1 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" About to create submitters thread 0: About to create submitters thread 1: About to create submitters thread 2: About to create submitters thread 3: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" About to create submitters thread 4: About to create reviewers thread 0: About to create reviewers thread 1: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.05 usr + 0.00 sys = 0.05 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.05 usr + 0.00 sys = 0.05 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread There are 7 threads A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined Processes ended - Goodbye Waiting to spawn processes. The submitters will run 4 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" The reviewers will run 1 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" About to create submitters thread 0: About to create submitters thread 1: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" About to create submitters thread 2: About to create submitters thread 3: About to create submitters thread 4: About to create reviewers thread 0: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" About to create reviewers thread 1: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.27 usr + 0.00 sys = 0.27 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 3 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 3 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread There are 7 threads A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined Processes ended - Goodbye Waiting to spawn processes. The submitters will run 4 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" The reviewers will run 1 times. The steps are: 0 = perl -wle"sleep int rand 3; print 'step1'" 1 = perl -wle"sleep int rand 3; print 'step2'" About to create submitters thread 0: About to create submitters thread 1: About to create submitters thread 2: About to create submitters thread 3: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" About to create submitters thread 4: About to create reviewers thread 0: About to create reviewers thread 1: starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.22 usr + 0.03 sys = 0.25 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.22 usr + 0.03 sys = 0.25 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 0 wallclock secs ( 0.22 usr + 0.02 sys = 0.23 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" starting thread About to run: perl -wle"sleep int rand 3; print 'step1'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 1 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step1'" 'step1 ' END perl -wle"sleep int rand 3; print 'step1'" output (time taken: 2 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) About to run: perl -wle"sleep int rand 3; print 'step2'" BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread BEGIN perl -wle"sleep int rand 3; print 'step2'" 'step2 ' END perl -wle"sleep int rand 3; print 'step2'" output (time taken: 1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)) Ending thread There are 7 threads A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined A thread joined Processes ended - Goodbye timethis 4: 14 wallclock secs ( 1.28 usr + 0.06 sys = 1.34 CPU) @ 2.98/s (n=4)