Make method_call benchmark use inheritance.

This also fixes a bug where constructors weren't being bound
correctly, and eliminates some unneeded instructions when
compiling ifs.

I also tweaked the other method_call languages to match Wren's.
Since Wren needs to do a super call to get to the parent _count,
the other languages do now too.

This is nice too because it means we're benchmarking super 
calls.
This commit is contained in:
Bob Nystrom
2013-12-18 07:37:41 -08:00
parent caafa96252
commit e7cf8ffe2e
7 changed files with 62 additions and 61 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ NthToggle = Toggle:new()
function NthToggle:activate ()
self.counter = self.counter + 1
if self.counter >= self.count_max then
self.state = not self.state
Toggle.activate(self)
self.counter = 0
end
return self
+2 -2
View File
@@ -4,7 +4,7 @@
import sys
import time
class Toggle:
class Toggle(object):
def __init__(self, start_state):
self.bool = start_state
def value(self):
@@ -21,7 +21,7 @@ class NthToggle(Toggle):
def activate(self):
self.counter += 1
if (self.counter >= self.count_max):
self.bool = not self.bool
super(NthToggle, self).activate()
self.counter = 0
return(self)
+1 -1
View File
@@ -29,7 +29,7 @@ class NthToggle < Toggle
def activate
@counter += 1
if @counter >= @count_max
@bool = !@bool
super
@counter = 0
end
self
+2 -31
View File
@@ -10,36 +10,8 @@ class Toggle {
}
}
class NthToggle {
this new(startState, maxCounter) {
_state = startState
_countMax = maxCounter
_count = 0
}
value { return _state }
activate {
_count = _count + 1
if (_count >= _countMax) {
_state = !_state
_count = 0
}
return this
}
}
// TODO: The follow the other examples, we should be using inheritance here.
// Since Wren doesn't currently support inherited fields or calling superclass
// constructors, it doesn't. It probably won't make a huge perf difference,
// but it should be fixed when possible to be:
/*
class NthToggle is Toggle {
this new(startState, maxCounter) {
// TODO: Need to distinguish superclass method calls from superclass
// constructor calls.
super.new(startState)
this new(startState, maxCounter) super.new(startState) {
_countMax = maxCounter
_count = 0
}
@@ -47,14 +19,13 @@ class NthToggle is Toggle {
activate {
_count = _count + 1
if (_count >= _countMax) {
_state = !_state
super.activate
_count = 0
}
return this
}
}
*/
var start = OS.clock
var n = 1000000