in reply to Sheer idle curiousity . . .

What does your intuition tell you this code does?

d=>sub{ $wait = 0 unless abs($wait); $wait = -34; },

In particular, abs returns the absolute value. The absolute value of -34 is 34, which is "true". Since your condition is never false, you never fall through to the action of the "unless" clause.


Dave

Replies are listed 'Best First'.
Re^2: Sheer idle curiousity . . .
by TheMonkWithoutVows (Novice) on Oct 23, 2013 at 22:16 UTC

    My intuition tells me it's been a long day and typos are creeping in :-)

    The last test should have read:

    d=>sub{ $wait = 0 unless ($wait == abs($wait)); $wait = -34; },
    I thought the results had shot up on my home pc.
    Rate d c b a d 3468819/s -- -8% -10% -13% c 3780923/s 9% -- -1% -5% b 3834916/s 11% 1% -- -4% a 3997317/s 15% 6% 4% -- and Rate d c b a d 3246175/s -- -8% -15% -17% c 3526456/s 9% -- -7% -9% b 3799184/s 17% 8% -- -2% a 3890565/s 20% 10% 2% --

    It's still the outright winner - so the questions still stand.

Re^2: Sheer idle curiousity . . .
by boftx (Deacon) on Oct 23, 2013 at 22:08 UTC

    Besides what David just said, it seems to me that the operation of simply setting a sign bit and then testing for 0 would inherently faster than any of the other comparisons if the resulting code is optimized. I know that would be the case if I were coding that in assembly.

    The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.
      if the resulting code is optimized.

      Its not. It just results in less opcodes.


      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.

        That was what I was driving at. I know that I could code that in 2 or 3 opcodes using nothing but bitwise operations if hand-coding. If the zero flag were set with a simple load then I could code it in a single opcode (excluding the jump codes.)

        The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.