Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #16 from zhuomingliang/master
Browse files Browse the repository at this point in the history
add point_class_add
  • Loading branch information
japhb committed Jan 9, 2015
2 parents 3c4b72a + a2cd0bd commit 25425c0
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 0 deletions.
10 changes: 10 additions & 0 deletions minibenchmarks.pl
Expand Up @@ -133,4 +133,14 @@
perl6 => [qw( BENCH/perl6/divide-and-conquer SCALE )],
nqp => undef,
},
{
name => 'point-class-add',
skip => [qw( )],
tags => [qw( stress attribute object-allocation multi-method)],
scale => 1 << 3,
expected => "650000001.5 950000002.5",
perl5 => undef,
perl6 => [qw( BENCH/perl6/point-class-add ), qw( BENCH/perl6/point-class-add1 ), qw( BENCH/perl6/point-class-add2 )],
nqp => [qw( BENCH/nqp/point-class-add ), qw( BENCH/nqp/point-class-add1 ), qw( BENCH/nqp/point-class-add2 ), qw( BENCH/nqp/point-class-add2-multi-method )],
},
]
26 changes: 26 additions & 0 deletions nqp/point_class_add
@@ -0,0 +1,26 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 1800+ NQP class NQP/MoarVM

# see perl6/point_class_add_README for more information

class Point {
has num $!x;
has num $!y;

method x() { $!x }
method y() { $!y }
method add(Point $b) {
return Point.new(:x($!x + $b.x), :y($!y + $b.y));
}
}
my int $i := 0;
my $a := Point.new(:x(1.5e0), :y(2.5e0));
my $b := Point.new(:x(3.25e0), :y(4.75e0));
while $i < 100000000 {
$a := $a.add($b).add($b);
$i := $i + 1;
}
print($a.x, ' ', $a.y);
29 changes: 29 additions & 0 deletions nqp/point_class_add1
@@ -0,0 +1,29 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 700+ NQP class NQP/MoarVM

# see perl6/point_class_add_README for more information

class Point {
has num $!x;
has num $!y;
method BUILD(num :$x, num :$y ) {
$!x := $x;
$!y := $y;
}
method x() { $!x }
method y() { $!y }
method add(Point $b) {
return self.bless(:x($!x + $b.x), :y($!y + $b.y));
}
}
my int $i := 0;
my $a := Point.new(:x(1.5e0), :y(2.5e0));
my $b := Point.new(:x(3.25e0), :y(4.75e0));
while $i < 100000000 {
$a := $a.add($b).add($b);
$i := $i + 1;
}
print($a.x, ' ', $a.y);
42 changes: 42 additions & 0 deletions nqp/point_class_add2
@@ -0,0 +1,42 @@
## Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 83 NQP class NQP/MoarVM

# see perl6/point_class_add_README for more information

class Point {
has num $!x;
has num $!y;
method new(num $x, num $y) {
my $self := nqp::create(self);
nqp::bindattr_n($self, Point, '$!x', $x);
nqp::bindattr_n($self, Point, '$!y', $y);

$self;
}

method x() { $!x }
method y() { $!y }

# multi method version makes it 2x slower
# but perl6 version with 'multi method add ' is about the same speed.
# proto method add($b) { * }
# multi method add(num $b) {
# }

# multi method add (Point $b) {
method add(Point $b) {
Point.new($!x + $b.x, $!y + $b.y);
}
}

my int $i := 0;
my $a := Point.new(1.5e0, 2.5e0);
my $b := Point.new(3.25e0, 4.75e0);
while $i < 100000000 {
$a := $a.add($b).add($b);
$i := $i + 1;
}
print($a.x, ' ', $a.y);
41 changes: 41 additions & 0 deletions nqp/point_class_add2_multi_method
@@ -0,0 +1,41 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 150 NQP class NQP/MoarVM

# see perl6/point_class_add_README for more information

class Point {
has num $!x;
has num $!y;
method new(num $x, num $y) {
my $self := nqp::create(self);
nqp::bindattr_n($self, Point, '$!x', $x);
nqp::bindattr_n($self, Point, '$!y', $y);

$self;
}

method x() { $!x }
method y() { $!y }

# multi method version makes it 2x slower
# but perl6 version with 'multi method add ' is about the same speed.
proto method add($b) { * }
multi method add(num $b) {
}

multi method add (Point $b) {
Point.new($!x + $b.x, $!y + $b.y);
}
}

my int $i := 0;
my $a := Point.new(1.5e0, 2.5e0);
my $b := Point.new(3.25e0, 4.75e0);
while $i < 100000000 {
$a := $a.add($b).add($b);
$i := $i + 1;
}
print($a.x, ' ', $a.y);
29 changes: 29 additions & 0 deletions perl6/point_class_add
@@ -0,0 +1,29 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 6600+ Perl6 class Rakudo/MoarVM

# see perl6/point_class_add_README for more information

use v6;

class Point {
has num $.x;
has num $.y;

method add(Point $b) {
return Point.new(:x($!x + $b.x), :y($!y + $b.y));
}
}

my int $i = 0;
my Point $a = Point.new(:x(1.5e0), :y(2.5e0));
my Point $b = Point.new(:x(3.25e0), :y(4.75e0));

while $i < 100000000 {
$a = $a.add($b).add($b);
$i = $i + 1;
}

print $a.x, ' ', $a.y;
34 changes: 34 additions & 0 deletions perl6/point_class_add1
@@ -0,0 +1,34 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 2500+ Perl6 class Rakudo/MoarVM

# see perl6/point_class_add_README for more information

use v6;

class Point {
has num $.x;
has num $.y;

submethod BUILD(num :$x, num :$y ) {
$!x = $x;
$!y = $y;
}

method add(Point $b) {
return self.bless(:x($!x + $b.x), :y($!y + $b.y));
}
}

my int $i = 0;
my Point $a = Point.new(:x(1.5e0), :y(2.5e0));
my Point $b = Point.new(:x(3.25e0), :y(4.75e0));

while $i < 100000000 {
$a = $a.add($b).add($b);
$i = $i + 1;
}

print $a.x, ' ', $a.y;
35 changes: 35 additions & 0 deletions perl6/point_class_add2
@@ -0,0 +1,35 @@
# Point Class Benchmarks

# Here's the runtime for the point class in seconds (YMMV). Lower is better:
# 0.22 Lua table LuaJIT 2.0 git HEAD -O+sink
# 420+ Perl6 class Rakudo/MoarVM

# see perl6/point_class_add_README for more information

use v6;

class Point {
has num $.x;
has num $.y;
method new(num $x, num $y) {
my Point $self = nqp::create(self);
nqp::bindattr_n($self, Point, '$!x', $x);
nqp::bindattr_n($self, Point, '$!y', $y);

$self;
}

method add(Point $b) {
Point.new($!x + $b.x, $!y + $b.y);
}
}
my int $i = 0;
my Point $a = Point.new(1.5e0, 2.5e0);
my Point $b = Point.new(3.25e0, 4.75e0);

while $i < 100000000 {
$a = $a.add($b).add($b);
$i = $i + 1;
}

print $a.x, ' ', $a.y;
17 changes: 17 additions & 0 deletions perl6/point_class_add_README
@@ -0,0 +1,17 @@
the code is ported from: http://wiki.luajit.org/Allocation-Sinking-Optimization

this benchmark is useful for Allocation Sinking Optimization or Escape Analysis Optimization

Point Class Benchmarks

Here's the runtime for the point class in seconds (YMMV). Lower is better:
Time Point object VM/Compiler
140 Lua table Lua 5.1.5
26.9 Lua table LuaJIT 2.0 git HEAD -O-sink
10.9 FFI struct LuaJIT 2.0 git HEAD -O-sink
0.2 Lua table LuaJIT 2.0 git HEAD -O+sink
0.2 FFI struct LuaJIT 2.0 git HEAD -O+sink
0.2 C++ class GCC 4.4.3 -O2 (or -O3)
1.2 Java class JVM/Hotspot 1.7.0_05

NOTE: the above is from Mike Pall.

0 comments on commit 25425c0

Please sign in to comment.