Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Of course, if numbers of words and/or terms is very large, and performance is critical, and you are prepared to throw memory at the problem, there is another, yet faster way. (How much faster is difficult to express in terms that most of us would understand).

The basic principle is an old favorite of mine: don't search; index. In this case that means building a hash that contains every possible variation of each word in the wordlist. For 'fred', that means adding '_red', 'f_ed', 'fr_d' & 'fre_' as keys to the hash with 'fred' as the values. Then, each of the wildcarded terms can be looked up directly. The result:

C:\test>junk42 -P=0.02 Looking for 3651 terms amongst 178691 words s/iter a b + c a 167 -- -95% + -100% b 8.20 1931% -- + -100% c 1.00e-015 16662499999999995902% 820299999999997696% + --

Which makes the process 8 quadrillion times faster than the regex against a string; and (an unbelievable) 166 quadrillion times faster than the regex engine over an array.

If my math is right, that means it can do in 1 second; what the regex engine would take 5 billion years to do!

(And I've checked and checked, and it really does appear to be true?)

The benchmark:

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^6: matching the words (166 quadrillion times faster!!) by BrowserUk
in thread matching the words by venky4289

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (3)
    As of 2018-03-18 20:16 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (230 votes). Check out past polls.