# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #111848]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=111848 >


<masak> r: my $t = now; my @a; @a[ $_ ] = $_ for 1 .. 1e4; print now - $t
<p6eval> rakudo 1968b8: OUTPUT«2.55866416794898»
<masak> r: my $t = now; my %h; %h{ $_ } = $_ for 1 .. 1e4; print now - $t
<p6eval> rakudo 1968b8: OUTPUT«1.51738952909994»
<masak> in Rakudo, hashes are faster than arrays :)
<masak> in re http://perlmonks.org/?node_id=960334
<moritz> masak: yes, it pays the price of laziness
<moritz> (it = Arrays)
<masak> moritz: even when, as here, I'm not using that laziness at all.
<moritz> masak: correct
<masak> what is the additional cost here, more exactly?
<moritz> well, for each array access we need to check if the number of
reified elements is big enough
<moritz> though that should be rather cheap-ish
<moritz> I kind think we're doing something very wrong when it comes
to arrays and lists
<moritz> nom: my @a = 1, 2, 3; say @a.DUMP
<p6eval> rakudo 1968b8: OUTPUT«Array<-4100004978996074906>(:items(Mu),
:nextiter(ListIter<-4100004978996073111>(:reified(▶Mu),
:rest(RPA<-4100004978996040334>(Array<-4100004978996076959>(:items(RPA<-4100004978996035975>(▶1,
▶2, ▶3)), :nextiter(▶Mu)))), :list(Array<-4100004978996074906>))))␤»…
<moritz> there you see what's wrong
<moritz> it's not the outer-most array that holds all the reified elements
<masak> right.
<moritz> they are stored in two layers of nextiter
<masak> I almost feel tempted to submit a rakudobug about that.
<moritz> please do
* masak submits rakudobug

Submitting bug reports about suboptimality is risky business. So
here's something concrete and actionable: remove the double nextiter
cruft from the above .DUMP output. Bonus points -- but not required to
close this ticket -- if you can get the benchmark above to run faster
too. Ideally, arrays should be faster than hashes.

Reply via email to