Skip to content

Instantly share code, notes, and snippets.

@pmichaud
pmichaud / gist:3033548
Created July 2, 2012 14:35
Guess how much memory this program uses?
pmichaud@kiwi:~/p6/parrot$ cat gc-sub.pir
.sub 'main' :main
.local int N
N = 1000000
$I0 = 0
loop:
unless $I0 < N goto done
'no-op'()
inc $I0
pmichaud@kiwi:~/p6/parrot$ ulimit -v
unlimited
pmichaud@kiwi:~/p6/parrot$ ./parrot gc.pir 1 # how much memory do we need for 1 rpa?
gc_mark_runs=0
gc_collect_runs=0
total_pmcs=2040
active_pmcs=1999
total_mem_alloc=663552
total_mem_used=318342
pmichaud@kiwi:~/p6/parrot$ # answer: 318KB
pmichaud@kiwi:~/p6/nqp$ ./nqp --target=past t001.nqp
"past" => PMC 'PAST;Block' {
<hll> => "nqp"
<loadinit> => PMC 'PAST;Stmts' {
[0] => PMC 'PAST;Stmts' {
[0] => PMC 'PAST;Stmt' {
[0] => PMC 'PAST;Stmts' {
[0] => PMC 'PAST;Op' {
<name> => "set_static_lexpad_value"
<pasttype> => "callmethod"
pmichaud@kiwi:~/p6/parrot$ cat gc-10.pir
.include 'interpinfo.pasm'
.sub 'main' :main
# This loop simply creates a large number of ResizablePMCArrays,
# releasing(?) any previously allocated RPA on each iteration
# through the loop.
$I0 = 0
pmichaud@kiwi:~/p6/parrot$ git describe --tags
RELEASE_4_5_0-7-g66923d2
pmichaud@kiwi:~/p6/parrot$ cat gc-1.pir
.include 'interpinfo.pasm'
.sub 'main' :main
# This loop simply creates a large number of ResizablePMCArrays,
The following uses the new --stagestats option to report on the amount
of memory consumed and PMCs allocated at each stage of compilation.
I'm running it on four NQP scripts; each script has one more "say(n);"
statement than the one before it.
-------Memory=------ ------PMCs------
Sec Alloc Used Total Active
pmichaud@kiwi:~/p6/nqp$ for i in x1 x2 x3 x4; do echo "$i:"; cat $i; ./nqp --stagestats=2 $i >/dev/null; echo ""; done
pmichaud@kiwi:~/p6/rakudo$ cat z
my @z = 1,4;
my $rop = &infix:<..>;
say $rop(|@z).perl;
my @zip := gather { my $r := $rop(|@z); say $r.perl; take $r; };
say @zip.perl;
pmichaud@kiwi:~/p6/rakudo$ cat z
my @z = 1,2;
my $rop = &infix:<..>;
say $rop(|@z).perl;
my @zip := gather { take $rop(|@z) };
say @zip.perl;
pmichaud@kiwi:~/p6/rakudo$ ./perl6 z
pmichaud@kiwi:~/p6/rakudo$ /usr/bin/time ./perl6 -e 'say "hello world"'
hello world
0.30user 0.10system 0:00.40elapsed 98%CPU (0avgtext+0avgdata 647152maxresident)k
0inputs+0outputs (0major+41933minor)pagefaults 0swaps
pmichaud@kiwi:~/p6/rakudo$ /usr/bin/time perl -MMoose -MMooseX::Method::Signatures -MMooseX::MultiMethods -e 'print "hello world\n"'
hello world
0.49user 0.03system 0:00.52elapsed 99%CPU (0avgtext+0avgdata 111552maxresident)k
0inputs+0outputs (0major+7074minor)pagefaults 0swaps
pmichaud@kiwi:~/p6/rakudo$
pmichaud@kiwi:~/p6/rakudo$ cat y.pir
.sub 'main'
$S0 = 'hello'
$P0 = split '', $S0
loop:
unless $P0 goto done
$S0 = shift $P0
say $S0
goto loop
done: