Hmm, I'm undecided about this. I've had a look over Quantum::Superpositions now, and it's got a lot of cool stuff in it. However, I see my approach as mostly syntactic sugar to replace things like:

if ($param eq 'this' || $param eq 'that' || $param eq 'the other') { ... }
with
if ($param eq any('this', 'that', 'the other') { ... }
which Quantum::Superpositions seems a bit overkill for.

Taking a hint from hardburn above, I did some benchmarks (below) and there is a significant runtime difference, between using my code and Quantum::Superpositions'.

One feature from Quantum::Superpositions that I think would be worth adding, is

$result = any(1,2,3) * 2; if ($result == 4) {...}
which would be trivial to add.

Tanktalus asked above about if (all(@x) eq any(@y) {...}. I can see how useful that would be, but would have to experiment to find a way to implement it without getting as big as Q::S, while not making the code too ugly.

Would Junction::Simple be a more fitting name? (I'm very hesitant to claim a top-name space)

Benchmark timings...

$ /usr/bin/perl ./benchmark.pl all: numeric (few) Rate Quantum-Superpositions Ju +nction Quantum-Superpositions 1842/s -- + -94% Junction 30303/s 1545% + -- all: numeric (lots) Rate Quantum-Superpositions Jun +ction Quantum-Superpositions 1364/s -- + -44% Junction 2433/s 78% + -- all: string Rate Quantum-Superpositions Jun +ction Quantum-Superpositions 1689/s -- + -79% Junction 8000/s 374% + -- any: numeric (few) Rate Quantum-Superpositions Ju +nction Quantum-Superpositions 747/s -- + -97% Junction 28571/s 3725% + -- any: numeric (lots) Rate Quantum-Superpositions Jun +ction Quantum-Superpositions 37.9/s -- + -97% Junction 1429/s 3672% + -- any: string Rate Quantum-Superpositions Jun +ction Quantum-Superpositions 317/s -- + -95% Junction 6422/s 1928% + --

And here's the test code:

#!/usr/bin/perl use strict; use warnings; use Junction qw/ xall xany /; use Quantum::Superpositions qw/ all any /; use Benchmark ':all'; print "all: numeric (few)\n"; cmpthese(30_000,{ Junction => sub { 1 if xall(1..5) == 2; }, 'Quantum-Superpositions' => sub { 1 if all(1..5) == 2; }, }); print "\nall: numeric (lots)\n"; cmpthese(30_000,{ Junction => sub { 1 if xall(1..300) == 250; }, 'Quantum-Superpositions' => sub { 1 if all(1..300) == 250; }, }); print "\nall: string\n"; cmpthese(10_000,{ Junction => sub { 1 if xall('a'..'z') eq 'z'; }, 'Quantum-Superpositions' => sub { 1 if all('a'..'z') eq 'z'; }, }); print "\nany: numeric (few)\n"; cmpthese(30_000,{ Junction => sub { 1 if xany(1..5) == 2; }, 'Quantum-Superpositions' => sub { 1 if any(1..5) == 2; }, }); print "\nany: numeric (lots)\n"; cmpthese(2_000,{ Junction => sub { 1 if xany(1..300) == 250; }, 'Quantum-Superpositions' => sub { 1 if any(1..300) == 250; }, }); print "\nany: string\n"; cmpthese(7_000,{ Junction => sub { 1 if xany('a'..'z') eq 'z'; }, 'Quantum-Superpositions' => sub { 1 if any('a'..'z') eq 'z'; }, });

In reply to Re: RFC: Junction.pm by fireartist
in thread RFC: Junction.pm by fireartist

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.