David-

I reran the final tests but included the vec approach
as well.  vec is roughly comparable with perl for
performance while PDL with indadd outperforms
the perl list approach somewhere between $N=100
and $N=1000.  PDL can be more than 3-6X faster
for large iteration counts.  Considering that PDL:

 - has the same memory footprint for processing vec

 - has much more powerful and flexible data manipulation

 - has simpler syntax for accessing elements (NiceSlice!)

 - does all of this is without custom XS, PP, or Inline::C

It is arguably the best alternative for this general
class of problems.  The output files from my
timing runs and the test code are attached.

--Chris

On Fri, Apr 20, 2012 at 2:52 PM, Chris Marshall <[email protected]> wrote:
> I reran the timings for both cygwin perl and
> asperl on the same computer (without the
> virus scan running) and got more consistent
> answers (without the low-$N anomalies) than
> from yesterday runs.
>
> The performance cross-over between perl and
> PDL is somewhere between $N=100 and
> $N=1000 with PDL being from 3-6X faster
> than perl for $N>10000.  I also note that
> cygwin is 2X slower than the native perl
> so there is good reason to make win32
> PDL fully compatable.  :-)
>
> $N         Cygwin   ASperl
> ---------------------------
> 1          0.02     0.02
> 10         0.05     0.08
> 100        0.4      0.6
> 1000       1.9      3.2
> 10000      3.4      6.6
> 100000     3.6      6.5
> 1000000    3.6      6.1
>
> --Chris
>
> On Fri, Apr 20, 2012 at 8:29 AM, David Mertens <[email protected]> 
> wrote:
>> No, I'm just not very experienced with Benchmarks. :-)
>>
>> I'll look into it later today.
>>
>> On Apr 19, 2012 4:29 PM, "Chris Marshall" <[email protected]> wrote:
>>>
>>> I notice you are still running a very small
>>> amount of timings.  How are your timings
>>> if you change the -1 to -10 in cmpthese?
>>> Is there a specific reason to leave that off
>>> of the update?
>>>
>>> --Chris
>>>
>>>
>>> On Thu, Apr 19, 2012 at 5:11 PM, David Mertens <[email protected]>
>>> wrote:
>>> > Wow, that makes a sizeable difference, especially for larger values of
>>> > $updates_per_round, where it doesn't need to constantly re-allocate
>>> > temporary memory. I've updated the post to reflect that.
>>> >
>>> > Thanks, Chris!
>>> > David
>>> >
>>> >
>>> > On Thu, Apr 19, 2012 at 3:19 PM, Chris Marshall <[email protected]>
>>> > wrote:
>>> >>
>>> >> I don't have a stackoverflow.com account but if I use
>>> >> your original test code, increase the cpu seconds for
>>> >> the benchmark and replace the dataflow increment
>>> >> code by the indadd() routine, I get speeds from 50X
>>> >> for $N=1, down to 1.9X for $N=1000, and then up to
>>> >> 3-4X as the sizes increase to 10000000 where I
>>> >> stopped testing.
>>> >>
>>> >> The key here is to avoid creating and destroying piddles
>>> >> since the computational work involved here is *very*
>>> >> light.  In fact, an Inline::PP routine to handle the core
>>> >> of an algorithm of interest (if more than indadd) + the
>>> >> existing PDL should perform very well for this use
>>> >> case---according to the benchmarks on my system:
>>> >>
>>> >> use PDL;
>>> >> use Benchmark qw/cmpthese/;
>>> >>
>>> >> my $updates_per_round = shift || 1;
>>> >>
>>> >> my $N = 1_000_000;
>>> >> my @perl = (0 .. $N - 1);
>>> >> my $pdl = zeroes $N;
>>> >>
>>> >> cmpthese(-10,{
>>> >>    perl => sub{
>>> >>        $perl[int(rand($N))]++ for (1..$updates_per_round);
>>> >>    },
>>> >>    pdl => sub{
>>> >>        my $to_update = long(random($updates_per_round) * $N);
>>> >>        indadd(1,$to_update,$pdl);
>>> >>        ## $pdl->index($to_update)++;
>>> >>    }
>>> >> });
>>> >>
>>> >>
>>> >> Cheers,
>>> >> Chris
>>> >>
>>> >> On Wed, Apr 18, 2012 at 10:11 AM, David Mertens
>>> >> <[email protected]> wrote:
>>> >> > Hey folks -
>>> >> >
>>> >> > There's a PDL question on stack overflow
>>> >> > (http://stackoverflow.com/questions/9730678/c-like-arrays-in-perl) to
>>> >> > which
>>> >> > I submitted an answer. I believe my answer is better than the
>>> >> > currently
>>> >> > marked best answer, but it looks like the OP either disagrees or
>>> >> > simply
>>> >> > has
>>> >> > not returned to read my answer. I would appreciate if those of you
>>> >> > who
>>> >> > have
>>> >> > stack overflow accounts could read the responses and up-vote what you
>>> >> > think
>>> >> > is the best answer.
>>> >> >
>>> >> > Thanks!
>>> >> > David
>>> >> >
>>> >> > --
>>> >> >  "Debugging is twice as hard as writing the code in the first place.
>>> >> >   Therefore, if you write the code as cleverly as possible, you are,
>>> >> >   by definition, not smart enough to debug it." -- Brian Kernighan
>>> >> >
>>> >> >
>>> >> > _______________________________________________
>>> >> > Perldl mailing list
>>> >> > [email protected]
>>> >> > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>>> >> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> >  "Debugging is twice as hard as writing the code in the first place.
>>> >   Therefore, if you write the code as cleverly as possible, you are,
>>> >   by definition, not smart enough to debug it." -- Brian Kernighan
>>> >
#!/usr/bin/perl
#
use PDL;
use Benchmark qw/cmpthese/;

my $N = 1_000_000;
my $updates_per_round = shift || 1;
my $vec = "\0" x ($N * 4);
my @perl = (0 .. $N - 1);
my $pdl = sequence(long,$N);

cmpthese(-20,
   {
      perl => sub{
         $perl[int(rand($N))]++ for (1..$updates_per_round);
      },
      pdl => sub{
         my $to_update = long(random($updates_per_round) * $N);
         indadd(1,$to_update,$pdl);
      },
      set => sub{
         for (1..$updates_per_round) {
            my $index = int(rand($N));
            $pdl->set($index,$pdl->at($index)+1);
         }
      },
      vec => sub {
         vec($vec, int(rand($N)), 32)++ for (1..$updates_per_round);; 
      },
   }
);
$N = 1
         Rate   pdl   set   vec  perl
pdl   11530/s    --  -88%  -98%  -98%
set   98826/s  757%    --  -86%  -86%
vec  714587/s 6098%  623%    --   -1%
perl 718834/s 6135%  627%    1%    --
$N = 10
         Rate   pdl   set   vec  perl
pdl   11284/s    --   -4%  -95%  -95%
set   11704/s    4%    --  -94%  -94%
vec  209793/s 1759% 1693%    --   -1%
perl 211958/s 1778% 1711%    1%    --

$N = 100
        Rate   set   pdl  perl   vec
set   1138/s    --  -89%  -96%  -96%
pdl  10034/s  782%    --  -62%  -62%
perl 26304/s 2212%  162%    --   -1%
vec  26654/s 2242%  166%    1%    --

$N = 1000
       Rate   set  perl   vec   pdl
set   114/s    --  -96%  -96%  -98%
perl 2685/s 2245%    --   -3%  -49%
vec  2775/s 2324%    3%    --  -47%
pdl  5281/s 4513%   97%   90%    --

$N = 10000
       Rate   set  perl   vec   pdl
set  11.4/s    --  -96%  -96%  -99%
perl  269/s 2257%    --   -1%  -72%
vec   273/s 2291%    1%    --  -72%
pdl   976/s 8443%  262%  257%    --

$N = 100000
       Rate   set  perl   vec   pdl
set  1.13/s    --  -96%  -96%  -99%
perl 27.2/s 2305%    --   -1%  -74%
vec  27.6/s 2336%    1%    --  -74%
pdl   107/s 9326%  292%  287%    --

$N = 1000000
        Rate   set  perl   vec   pdl
set  0.114/s    --  -96%  -96%  -99%
perl  2.67/s 2251%    --   -2%  -74%
vec   2.71/s 2288%    2%    --  -74%
pdl   10.4/s 9095%  291%  285%    --
$N = 1
          Rate   pdl   set   vec  perl
pdl    22350/s    --  -86%  -98%  -98%
set   162641/s  628%    --  -82%  -85%
vec   902084/s 3936%  455%    --  -15%
perl 1062223/s 4653%  553%   18%    --

$N = 10
         Rate   set   pdl   vec  perl
set   19940/s    --   -4%  -92%  -93%
pdl   20787/s    4%    --  -91%  -92%
vec  241356/s 1110% 1061%    --  -12%
perl 273586/s 1272% 1216%   13%    --

$N = 100
        Rate   set   pdl   vec  perl
set   1973/s    --  -90%  -93%  -94%
pdl  19679/s  897%    --  -33%  -36%
vec  29222/s 1381%   48%    --   -6%
perl 30954/s 1469%   57%    6%    --

$N = 1000
        Rate   set   vec  perl   pdl
set    195/s    --  -93%  -94%  -98%
vec   2944/s 1408%    --  -12%  -74%
perl  3330/s 1606%   13%    --  -71%
pdl  11337/s 5708%  285%  240%    --

$N = 10000
       Rate    set    vec   perl    pdl
set  20.1/s     --   -93%   -94%   -99%
vec   297/s  1377%     --   -18%   -88%
perl  363/s  1705%    22%     --   -85%
pdl  2425/s 11959%   717%   568%     --

$N = 100000
       Rate    set    vec   perl    pdl
set  2.04/s     --   -93%   -94%   -99%
vec  29.0/s  1325%     --   -20%   -88%
perl 36.5/s  1693%    26%     --   -85%
pdl   242/s 11775%   733%   562%     --

$N = 1000000
        Rate    set    vec   perl    pdl
set  0.195/s     --   -93%   -94%   -99%
vec   2.76/s  1312%     --   -21%   -88%
perl  3.49/s  1691%    27%     --   -85%
pdl   23.4/s 11917%   751%   571%     --
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to