Skip to content

Instantly share code, notes, and snippets.

@thwarted
Created December 16, 2009 17:56
Show Gist options
  • Save thwarted/258016 to your computer and use it in GitHub Desktop.
Save thwarted/258016 to your computer and use it in GitHub Desktop.
perl threads perf
#!/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