Created
December 16, 2009 17:56
-
-
Save thwarted/258016 to your computer and use it in GitHub Desktop.
perl threads perf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use threads; | |
use threads::shared; | |
use Thread::Queue; | |
my @times = ("startup@".time); | |
my $bigdata = 0xdeadbeef x (1024 * 1024 * 3); | |
# make this big structure shared between threads to see performance differences | |
# with thread spawning times | |
# my @bigarray :shared = (); | |
my @bigarray = (); | |
for my $y (1..20) { | |
push(@bigarray, "$bigdata"); | |
} | |
push(@times, "fillmem@".time); | |
sub subthread { | |
print "in subthread\n"; | |
} | |
my @threads = (); | |
push(@threads, threads->new(\&subthread)); | |
push(@times, " thr1@".time); | |
push(@threads, threads->new(\&subthread)); | |
push(@times, " thr2@".time); | |
push(@threads, threads->new(\&subthread)); | |
push(@times, " thr3@".time); | |
while (@threads) { | |
my $t = shift @threads; | |
$t->join; | |
} | |
push(@times, " finish@".time); | |
print Dumper(\@times); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment