Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from zhuomingliang/master
add point_class_add
- Loading branch information
Showing
9 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |