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

  1. starting a new thread--a few milliseconds at most.
  2. Unless you've shared @allips, then that array will be copied into the new thread.

    That's pure overhead.

  3. copying the results set from the new thread back to the main thread.

    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.


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.
RIP an inspiration; A true Folk's Guy

In reply to Re: Is Using Threads Slower Than Not Using Threads? by BrowserUk
in thread Is Using Threads Slower Than Not Using Threads? by Dru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.