#! perl -slw use strict; use threads; use Time::HiRes 'time'; our $T //= 4; my @threads; my $start = time; foreach my $i (1 .. $T ) { $threads[$i] = threads->create(\&Work, $i); } foreach my $i ( 1 .. $T ) { $threads[$i]->join(); } my $stop = time - $start; printf "\nclock: %f sec user: %f\n", $stop, (times())[0]; exit; ##### sub Work { my ($i) = @_; foreach ( 1 .. ( 20e5 / $T ) ) { my $acct_nrs = "abc\txyz\tdef\tabc\tghi\tghi"; my @temp = split(m/\t/, $acct_nrs, -1); @temp = ( sort keys %{{ map { $_ => 1 } @temp }} ); my $ans = join(', ', @temp); } printf " $i"; return; } __END__ C:\test>for /l %i in (1,1,4) do @972137 -T=%i 1 clock: 29.351637 sec user: 29.093000 1 2 clock: 14.986346 sec user: 29.765000 1 2 3 clock: 10.131188 sec user: 29.968000 2 3 4 1 clock: 7.781729 sec user: 29.796000 #### C:\test>for /l %i in (1,1,4) do @\perl64-14\bin\perl.exe -slw 972137.pl -T=%i 1 clock: 27.309776 sec user: 27.343000 2 1 clock: 13.878018 sec user: 27.625000 2 1 3 clock: 9.370494 sec user: 27.875000 3 2 1 4 clock: 7.205594 sec user: 27.765000