Joe Wilson writes: > Dan Sugalski: > > 2) Parrot's Array and SArray values all accept mixed-type data, which > > perl's arrays do *not* do, and as such have some extra speed hits > > that perl arrays don't. > > What do you mean? > Perl's arrays do indeed accept mixed data types (see example below).
No, they don't. They are arrays of PerlScalars only. For this: set P1, P0[35] The current Array and SArray have to sift through the sparse table to find the 35th index (that's pretty efficient, but it still needs to check whether it needs to do that). It then checks whether the 35th element is indeed a PMC (it could be an int, num, or str), and then sets P1 to that element. Perl's array doesn't have sparse handling (the timing of perl -le '$x[10000000] = 1' should convince you of this), and it doesn't need to check whether the 35th element is a scalar, because the only thing it holds are scalars. Luke > $ cat addit2.pl > #!/usr/bin/perl > # > # addit2.pl > # > use strict; > sub varargs_adder { > my $sum = 0; > for (my $a = $#_; $a >= 0; --$a) { > $sum += $_[$a]; > } > return $sum > } > my $result = 0; > my @args; > $args[0] = 1000; > $args[1] = 7.100; > $args[2] = 87; > $args[3] = "3.87"; > $args[4] = "21000000"; > for (my $x = 500000; $x >= 0; --$x) { > $result = varargs_adder(@args); > } > print "$result\n"; > > $ time perl addit2.pl > 21001097.97 > > real 0m2.825s > user 0m2.843s > sys 0m0.015s > > $ cat f6.pasm > # > # f6.pasm > # > # array element arguments are created before the loop > # > _main: > new P5, .SArray > set P5, 5 > push P5, 1000 > push P5, 7.100 > push P5, 87 > push P5, "3.87" > push P5, "21000000" > set I9, 500000 > AGAIN: > dec I9 > lt I9, 0, FIN > bsr _varargs_adder > branch AGAIN > FIN: > print N0 > print "\n" > end > _varargs_adder: > new P2, .PerlNum > assign P2, 0 > set I1, P5 > LOOP: > dec I1 > lt I1, 0, DONE > set P1, P5[I1] > add P2, P2, P1 > branch LOOP > DONE: > set N0, P2 > ret > > > $ time parrot f6.pasm > 21001097.970000 > > real 0m3.925s > user 0m3.936s > sys 0m0.015s > > > $ time parrot -j f6.pasm > 21001094.100000 (note: wrong result and slower with jit) > > real 0m11.999s > user 0m12.015s > sys 0m0.000s > > > > __________________________________ > Do you Yahoo!? > New Yahoo! Photos - easier uploading and sharing. > http://photos.yahoo.com/