On Sun Feb 10 02:05:54 2013, nicholas wrote:
> On Mon Mar 19 11:34:12 2012, pmichaud wrote:
> > The speed of Array vs. Hash element access is partially addressed by 
> > commit c10792f8.  Before this commit, each Array element access via 
> > .at_pos($pos) resulted in an expensive call to self.exists($pos) for 
> > each access, whereas Hash element accesses via .at_key($key) were 
> > able to use nqp::existskey() directly.  This patch uses nqp::existspos() 
> > to hotpath the detection of existing elements and avoids calls to 
> > self.exists($pos) when the Array is already fully reified.  
> > 
> > For the benchmark given in RT #111848, this resulted in a ~25%
> > speedup for array element accesses, and brings it to within 5% of Hash
> > element access times.  (At present Array element accesses still have
> > more overhead at the PIR level than Hash element accesses due to
> > laziness considerations and boundary checks.
> 
> Timings remain roughly consistent today (at a3869a037bb10552):
> 
> $ ./perl6 -e 'my $t = now; my @a; @a[ $_ ] = $_ for 1 .. 1e4; say now - $t'
> 1.3921895
> $ ./perl6 -e 'my $t = now; my %h; %h{ $_ } = $_ for 1 .. 1e4; say now - $t'
> 1.30200286
> 
> with hashes still faster.
> 
> Nicholas Clark

Ran this today with rakudo-m:

$ ./perl6 -e 'my $t = now; my @a; @a[ $_ ] = $_ for 1 .. 1e4; say now - $t'
0.0565928
$ ./perl6 -e 'my $t = now; my %h; %h{ $_ } = $_ for 1 .. 1e4; say now - $t'
0.06960988

Not only are they both much faster, arrays are now faster than hashes.

Closing ticket.

-- 
Will "Coke" Coleda

Reply via email to