in reply to Threads From Hell #1: How To Share A Hash [SOLVED]
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Threads From Hell #1: How To Share A Hash [SOLVED]
by karlgoethebier (Abbot) on May 15, 2015 at 18:34 UTC | |
Re^2: Threads From Hell #1: How To Share A Hash [SOLVED]
by karlgoethebier (Abbot) on May 16, 2015 at 11:31 UTC | |
by BrowserUk (Patriarch) on May 16, 2015 at 12:46 UTC | |
by karlgoethebier (Abbot) on May 17, 2015 at 09:01 UTC | |
by BrowserUk (Patriarch) on May 17, 2015 at 13:37 UTC | |
by karlgoethebier (Abbot) on May 17, 2015 at 14:29 UTC | |
|