"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Corion kindly advised my not to use Thread::Semaphore and pointed me to ... Thread::Queue. I finally got around to putting together proof of the wisdom of Corion's advice. This is a version of your Thread::Semaphore code, limiting to 4 concurrent threads and calculating factorials 1000! .. 2000!: Total runtime: Took 47.511607 seconds This version does the same calculations using the same number of concurrent threads, but ditches Thread::Semaphore in favour of Thread::Queue to queue the 1000 numbers to 4 reused threads, thus saving the startup and teardown costs of 996 threads: Total runtime: Took 31.290966 seconds; giving a 33% saving of time. But the biggest lesson of threading, is when not to use it. This version ditches threads altogether and uses the obvious optimisation: Total runtime: Took 0.685503 seconds. Same results, but a 98.5% time saving over the first version above. 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".
I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
In reply to Re: Threads From Hell #1: How To Share A Hash [SOLVED]
by BrowserUk
|
|