A presentation by Mikhael Goikhman from a 2003 Perl conference includes a pair of examples of prime-number-finding scripts. One is threaded, and the other is not. Upon running the scripts (print lines commented out), I got an execution time of 0.011s on the non-threaded one, and 2.343 (!) seconds on the threaded version. What accounts for the stunning difference in times?
I have some experience with threads in Perl and have noticed before that thread creation times can be particularly brutal, but this doesn't seem to be the bottleneck in Goikham's example.
Jay P. is right:
~$ strace -c ./threads.pl
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.80 0.116007 10546 11 futex
0.20 0.000229 6 36 mmap2
0.00 0.000000 0 31 read
0.00 0.000000 0 49 13 open
0.00 0.000000 0 36 close
Compare that with:
~$ strace -c ./no-threads.pl
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
90.62 0.000261 261 1 execve
9.38 0.000027 0 167 write
0.00 0.000000 0 12 read
0.00 0.000000 0 38 13 open
0.00 0.000000 0 25 close
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With