Re: NQP JVM prototype faster than Perl 5
On Sat, Feb 02, 2013 at 06:32:10PM -0800, Matthew Wilson wrote: Did you mean to use $z in the say output of the nqp and perl versions of the microbenchmark, or did you mean to run it twice? I didn't write the nqp microbenchmark, and I simply transcribed it to Perl 5, so it's intentional. I didn't spot it, thanks for noticing. It doesn't actually change the numbers, because the timing is still for one call. But it does cause the program to do a lot less work to get there. $ cat ~/Perl/rakudo/nqp/examples/fib.nqp #! nqp sub fib($n) { $n 2 ?? $n !! fib($n-1) + fib($n - 2); } my $N := @ARGS 1 ?? @ARGS[1] !! 29; my $t0 := nqp::time_n(); my $z := fib($N); my $t1 := nqp::time_n(); nqp::say(fib($N) = $z); nqp::say(time= ~ ($t1-$t0)); $ nqp ~/Perl/rakudo/nqp/examples/fib.nqpfib(29) = 514229 time= 3.2875030040741 $ nqp nqp-jvm-cc.nqp ~/Perl/rakudo/nqp/examples/fib.nqp fib(29) = 514229 time= 0.3913242492676 and Perl 5: $ cat ~/test/fib.pl #! perl use Time::HiRes 'time'; sub fib { my $n = shift; $n 2 ? $n : fib($n-1) + fib($n - 2); } my $N = @ARGV 1 ? $ARGV[0] : 29; my $t0 = time; my $z = fib($N); my $t1 = time; print fib($N) = $z\n; print time= . ($t1-$t0) . \n; $ ~/Sandpit/5162/bin/perl5.16.2 ~/test/fib.pl fib(29) = 514229 time= 0.5503830909729 Nicholas Clark
Re: NQP JVM prototype faster than Perl 5
On Sun, Feb 03, 2013 at 10:35:12AM +, Nicholas Clark wrote: On Sat, Feb 02, 2013 at 06:32:10PM -0800, Matthew Wilson wrote: Did you mean to use $z in the say output of the nqp and perl versions of the microbenchmark, or did you mean to run it twice? I didn't write the nqp microbenchmark, and I simply transcribed it to Perl 5, so it's intentional. I didn't spot it, thanks for noticing. not intentional. Oops Nicholas Clark
NQP JVM prototype faster than Perl 5
This is surprising, interesting and pleasing... There's some example NQP code to time calculating Fibonacci sequences. I've tweaked it a tiny bit to take an optional count on the command line. Unfortunately the NQP JVM prototype doesn't yet set @ARGS, so this isn't that useful. Anyway, the code is: $ cat ~/Perl/rakudo/nqp/examples/fib.nqp #! nqp sub fib($n) { $n 2 ?? $n !! fib($n-1) + fib($n - 2); } my $N := @ARGS 1 ?? @ARGS[1] !! 29; my $t0 := nqp::time_n(); my $z := fib($N); my $t1 := nqp::time_n(); nqp::say(fib($N) = ~ fib($N)); nqp::say(time= ~ ($t1-$t0)); Running with NQP (optimised build): $ nqp ~/Perl/rakudo/nqp/examples/fib.nqp fib(29) = 514229 time= 3.15967702865601 Running with the NQP JVM prototype: $ nqp nqp-jvm-cc.nqp ~/Perl/rakudo/nqp/examples/fib.nqp fib(29) = 514229 time= 0.4210381469727 That's about 8 times faster. (Even including all the compiling, right now it's actually still faster. About 2.5 times faster) And the equivalent Perl 5 code: $ cat ~/test/fib.pl #! perl use Time::HiRes 'time'; sub fib { my $n = shift; $n 2 ? $n : fib($n-1) + fib($n - 2); } my $N = @ARGV 1 ? $ARGV[0] : 29; my $t0 = time; my $z = fib($N); my $t1 = time; print fib($N) = . fib($N) . \n; print time= . ($t1-$t0) . \n; $ ~/Sandpit/5162/bin/perl5.16.2 ~/test/fib.pl fib(29) = 514229 time= 0.544455051422119 So the NQP JVM prototype is about 1.5 faster at running that code than Perl 5. That's without any sort of tuning of its code generator. That's quite impressive. Well done Jonathan. Please don't stop :-) Nicholas Clark