in reply to Re^5: Speed Improvement
in thread Speed Improvement

yours and McA's algorithms performed slightly worse,

studying takes time and rarely yields enough extra performance to cover the cost, unless you are searching very long strings -- eg. whole files -- repeatedly. Ie. study once; search many times.

definitely not a no-op,

I think if you look back at Dave_the_M's post you'll see that he said "a noop since 5.16". (I'm assuming the use 5.10; is indicative of what you are using?)


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.

Replies are listed 'Best First'.
Re^7: Speed Improvement
by GotToBTru (Prior) on Dec 02, 2014 at 16:33 UTC

    No, I'm running 5.20.1, at least on my pc. I took out the use 5.010 and the results are pretty much the same -- something is happening, but nothing good. Yes, study takes the time to build a table to make searching more efficient, something akin to a database index. If the strings are short, or there are only a very few searches to perform, study isn't worth the effort. I should really try it on a sample problem like the one suggested in the docs.

    1 Peter 4:10
      No, the study keyword does absolutely nothing except return an appropriate boolean for backwards compatibilty. In particular, it is not building up any tables. Here is the C source code for pp_study() in 5.18.0:
      PP(pp_study) { dVAR; dSP; dPOPss; STRLEN len; (void)SvPV(sv, len); if (len == 0 || len > I32_MAX || !SvPOK(sv) || SvUTF8(sv) || SvVAL +ID(sv)) { /* Historically, study was skipped in these cases. */ RETPUSHNO; } /* Make study a no-op. It's no longer useful and its existence complicates matters elsewhere. */ RETPUSHYES; }

      Dave.

      something is happening,

      I'm guessing the differences you are seeing is just down to the overhead of calling into C, doing (almost) nothing, and returning again.

      From pp.c/5.18

      /* Pattern matching */ PP(pp_study) { dVAR; dSP; dPOPss; STRLEN len; (void)SvPV(sv, len); if (len == 0 || len > I32_MAX || !SvPOK(sv) || SvUTF8(sv) || SvVAL +ID(sv)) { /* Historically, study was skipped in these cases. */ RETPUSHNO; } /* Make study a no-op. It's no longer useful and its existence complicates matters elsewhere. */ RETPUSHYES; }

      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.