in reply to Is Using Threads Slower Than Not Using Threads?
Effectively, you've done the equivalent of loading your car onto the back of a transporter and driving the transporter to all your appointments. Needless to say, using two vehicles in this way does not speed up your deliveries, and costs the time it takes getting the car on and off the transporter.
What your code does is simply move the code that would be in the main (initial;startup) thread, into a new thread.
As such, you're only making use of one thread--the main thread just sits blocked, doing nothing until the new thread completes--so it won't speed anything up.
But, you've added the costs of
That's pure overhead.
More overhead.
So yes. The way you are going about it, using a thread that way will be slower than not using them.
As other have said, the first way to speed up your program will be to use a better algorithm.
However, if your machine has multiple cores--once you've avoided searching every line 3500 times, and made sure that you're using the fastest search mechanism Perl has to offer--then there might be some further gains to be had by using threading effectively.
Of course, once you've made the algorithm changes, you might be running quickly enough and not need to use threading. But if you'd like to investigate usng threads properly, speak up.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Is Using Threads Slower Than Not Using Threads? (copying)
by tye (Sage) on Nov 01, 2010 at 17:40 UTC | |
| |
Re^2: Is Using Threads Slower Than Not Using Threads?
by ysth (Canon) on Nov 07, 2010 at 09:45 UTC | |
by BrowserUk (Patriarch) on Nov 07, 2010 at 10:19 UTC | |
by ysth (Canon) on Nov 07, 2010 at 22:13 UTC | |
by BrowserUk (Patriarch) on Nov 07, 2010 at 22:31 UTC | |
by tye (Sage) on Nov 08, 2010 at 01:47 UTC | |
|