Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Horse64 version of the method call benchmark #2

Merged
merged 1 commit into from Feb 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/method-call.h64
@@ -0,0 +1,71 @@

class Toggle {
var state protect = no

func init(start_state=no) {
self.state = (start_state == yes)
}

func activate {
self.state = not self.state
}
}

class NthToggle {
var num_state protect = 0
var max_value = 0
var toggle = new Toggle()
var state protect = no
var counter = 0

func init(max_value, start_state=no) {
self.max_value = (0 + max_value)
self.state = no
if start_state {
self.state = yes
self.toggle.activate()
}
}

func activate {
self.counter += 1
if self.counter >= self.max_value {
self.toggle.activate()
self.state = self.toggle.state
self.counter = 0
}
}
}

func main {
var N = 100000

var val = yes
var toggle = new Toggle(start_state=val)
var i = 1
while i <= N {
var i2 = 1
while i2 <= 10 {
toggle.activate()
val = toggle.state
i2 += 1
}
i += 1
}
print(val)

val = yes
var ntoggle = new NthToggle(3, start_state=val)
i = 1
while i <= N {
var i2 = 1
while i2 <= 10 {
ntoggle.activate()
val = ntoggle.state
i2 += 1
}
i += 1
}
print(val)
}