+6  A: 

I ran the source code through the Devel::SmallProf profiler. The profile output is a little too verbose to post here, but you can see the results yourself using $ perl -d:SmallProf chameneos.pl 10000 (no need to run it for 6000000 meetings unless you really want to!) See perlperf for more details on some profiling tools in Perl.

It turns out that using semaphores is the major bottleneck. The lion's share of total CPU time is spent on checking whether a semaphore is locked or not. Although I haven't had enough time to look at why the source code uses semaphores, it may be that you can work around having to use semaphores altogether. That's probably your best shot at improving the code's performance.

Zaid
I could have told you without profiling, there really wasn't anything else that could that much time. The question is: what to do about it though.
Leon Timmermans
+2  A: 

As Zaid posted, Thread::Semaphore is rather slow. One optimization could be to use the implicit locks on shared variables instead of them. It should be faster, though I suspect it won't be faster by much.

In general, Perl's threading implementation sucks for any kind of usage that requires a lot of interthread communication. It's very suitable for tasks with little communication (as unlike CPython's threads and CRuby's threads they are actually preemptive).

It may be possible to improve that situation, we need better primitives.

Leon Timmermans
I hadn't realized that (C)Ruby got that so far wrong too.
Donal Fellows
+1  A: 

Anyone tried s/threads/forks/ on the Perl entry? Or Coro / Coro::MP, though the latter would probably trigger the 'interesting alternative implementations' clause.

MkV
+2  A: 

I have a version based on another version from Jesse Millikian, which I think was never published.

I think it may run ~ 7x faster than the current entry, and uses standard modules all around. I'm not sure if it actually complies with all the rules though.

I've tried the forks module on it, but I think it slows it down a bit.

rodrigo