>>>>> "JP" == Jerrad Pierce <[EMAIL PROTECTED]> writes:

  JP> In case anyone is interested:
  JP> ANY:
  JP>       s/iter    QS    P6
  JP> QS      1.22    --  -98%
  JP> P6 2.04e-002 5889%    --

  JP> ALL:
  JP>      Rate    QS    P6
  JP> QS 1.44/s    --  -98%
  JP> P6 78.0/s 5318%    --

quite a speedup.

you can make the benchmark more accurate by factoring out some of the
work you are doing in each call.


  JP> package main;
  JP> use Benchmark;

  JP> sub ANY{
  JP>   if( &{$_[0].'::any'}(1 .. 10_000) > 10_001 ){
  JP>     warn "This should not happen\n";
  JP>   }
  JP>   if( &{$_[0].'::any'}(1 .. 10_000) == 42 ){
  JP>     #print "The Answer\n";
  JP>   }
  JP> }
  JP> sub ALL{
  JP>   unless( &{$_[0].'::all'}(1 .. 10_000) < 10_001 ){
  JP>     warn "This should not happen\n";
  JP>   }
  JP> }

declare my @int = 1 .. 10_000 outside the subs and remove that building
of the list each time.

also you are doing symrefs which are slow. you can easily change this to
use code refs.

<untested>

my @ints = ( 1 .. 10_000 ) ;

sub ALL{
  unless( $_[0]->( @ints ) < 10_001 ){
    warn "This should not happen\n";
  }
}

sub ANY{
  if( $_[0]->( @ints ) > 10_001 ){
    warn "This should not happen\n";
  }
  if( $_[0]->( @ints ) == 42 ){
    #print "The Answer\n";
  }
}

Benchmark::cmpthese(50,
                    {
                     P6=>sub{ ANY \&Perl6::Junction::any },
                     QS=>sub{ ANY \&Quantum::Superpositions::any }
                    });


Benchmark::cmpthese(50,
                    {
                     P6=>sub{ ALL \&Perl6::Junction::all },
                     QS=>sub{ ALL \&Quantum::Superpositions::all }
                    });

i don't have those installed but i would be curious as the new numbers
as the changes will emphasize the any/all code more this way.

and also try a range of list sizes. some algorithms work better with
different sized inputs. you could automate that with a array of int
lists and them also passing in a ref to one of those in the benchmark
calls. then just loop over the int lists and you can get a table of
results with multiple input sizes.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to