Although I can't test it right now, I sincerely doubt that your version is faster, especially if you compare the optrees:

My version:

LISTOP (0x4b240) leave [1] OP (0x4b270) enter COP (0x4b200) nextstate UNOP (0x4b1e0) null LOGOP (0x4b1b0) or UNOP (0x53d20) postinc [2] BINOP (0x53cf0) helem UNOP (0x4d8b0) rv2hv SVOP (0x4d8f0) gv GV (0x511cc) *s UNOP (0x53cd0) lc [1] UNOP (0x53cb0) null [15] SVOP (0xaec40) gvsv GV (0x4753c) *_ LISTOP (0x4d910) print OP (0x4dea0) pushmark UNOP (0x4b190) null [15] SVOP (0x4d940) gvsv GV (0x4753c) *_
Your version:
LISTOP (0x4b260) leave [1] OP (0x4b290) enter COP (0x4b220) nextstate UNOP (0x4b200) null LOGOP (0x4d940) and BINOP (0x4d910) eq SVOP (0xaec40) const IV (0x47650) 1 UNOP (0x4dea0) preinc BINOP (0x4b1d0) helem UNOP (0x53d10) rv2hv SVOP (0x546b0) gv GV (0x51148) *s UNOP (0x4b1b0) lc [1] UNOP (0x4b190) null [15] SVOP (0x53d30) gvsv GV (0x4753c) *_ LISTOP (0x58490) print OP (0x584c0) pushmark UNOP (0x4d8b0) null [15] SVOP (0x4d8f0) gvsv GV (0x4753c) *_

While your version does save copying the old integer value to a temporary (you realize the temporary sv is allocated at compile-time, right?), it takes two extra ops, which I'm pretty sure costs more cpu time.

And in any case the difference is too minimal (especially compared to lowercasing the string and doing a hash lookup) to justify adding to the code complexity


In reply to Re: Re: Re: state preserving uniq by xmath
in thread state preserving uniq by Chady

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.