In some of my recent code I've been using the trinary operator a lot. I suspect it may be slightly faster since it doesn't involve opening code blocks and is an operator instead of a keyword (this may be a load of bulshit, mind you)...

So....I figure I'll benchmark it. Great...I can't seem to devise good test cases.

This brings me to call upon the wisdom of my fellow Monks. First off, can somebody help me figure out some good test cases. Maybe even give me some generic guidelines for creating test cases to use with Benchmark.pm. And....if anybody happens to know off the top of their head the speed differences between the two, that'd be helpful too. ::smile::

I understand that the trinary obfuscates the code a degree...but if it gains a speed boost, I can comment it to hell and back. The thought just occured to me...does the optimizer change an If'n'Else into a trinary anyway?


In reply to Trinary or If'n'Else? by SamQi

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.