|Welcome to the Monastery|
Re: Is Using Threads Slower Than Not Using Threads?by BrowserUk (Pope)
|on Nov 01, 2010 at 09:16 UTC||Need Help??|
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
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.
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".
In the absence of evidence, opinion is indistinguishable from prejudice.