specifying primitive data types in Perlito5

I'm trying out this new little benchmark, which imports Java primitive data types into a Perl script:

# misc/benchmark/benchmark_typed_primitive.pl
package long {}
my long $count = 0;
my long $i = 0;
while ( $i < 400 ) {
    my long $j = 0;
    while ( $j < 400 ) {
        my long $k = 0;
        while ( $k < 400 ) {
            $k = $k + 1;
            $count = $count + 1;
        }
        $j = $j + 1;
    }
    $i = $i + 1;
}
my $c = $count;
print "done $c\n";

Comparing with the previous benchmarks:

Plain perl script:

$ time perl misc/benchmark/benchmark_lexical.pl
done 64000000

real    0m4.070s    # base time (1x)
user    0m4.064s
sys 0m0.008s

The same untyped Perl script, running as Perl-in-Java, compilation time excluded:

$ perl perlito5.pl -Isrc5/lib -I. -It -Cjava misc/benchmark/benchmark_lexical.pl > Main.java ; javac Main.java ; time java Main
done 64000000

real    0m0.985s    # 4x faster
user    0m0.626s
sys 0m0.461s

Perl script with primitive types added, running as Perl-in-Java, compilation time excluded:

$ perl perlito5.pl -Isrc5/lib -I. -It -Cjava misc/benchmark/benchmark_typed_primitive.pl  > Main.java ; javac Main.java ; time java Main
done 64000000

real    0m0.102s    # 40x faster
user    0m0.086s
sys 0m0.013s

Just to be sure this is valid Perl:

$ perl -c misc/benchmark/benchmark_typed_primitive.pl
misc/benchmark/benchmark_typed_primitive.pl syntax OK

Compilation time from Perl to Java is:

$ time ( perl perlito5.pl -Isrc5/lib -I. -It -Cjava misc/benchmark/benchmark_typed_primitive.pl  > Main.java ; javac Main.java )

real    0m1.356s
user    0m2.610s
sys 0m0.072s

These command lines run from the root directory of https://github.com/fglock/Perlito checkout; the little benchmark code is at https://github.com/fglock/Perlito/blob/master/misc/benchmark.

Leave a comment

About Flávio S. Glock

user-pic I blog about Perl.