In summary, my questions are:
Are you running Windows in a VM? That's the only thing that comes to mind that might explain your results. I cannot reproduce them at all
I only have 4 cores, and the result from your script (slightly tweaked) show an almost perfect split of processing:
#! 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
Update: Ditto for 5.14:
C:\test>for /l %i in (1,1,4) do @\perl64-14\bin\perl.exe -slw 972137.p
+l -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
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.