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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user