From: fennecdjay Date: Mon, 1 Jul 2019 17:10:13 +0000 (+0200) Subject: :white_check_mark: More benchmarks X-Git-Tag: nightly~2382^2~5 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=refs%2Fpull%2F138%2Fhead;p=gwion.git :white_check_mark: More benchmarks --- diff --git a/tests/benchmark/method_call.ck b/tests/benchmark/method_call.ck new file mode 100644 index 00000000..e2029da7 --- /dev/null +++ b/tests/benchmark/method_call.ck @@ -0,0 +1,72 @@ +class Toggle { + int state; + fun int value() { return state; } + fun Toggle activate() { +//<<<"supr">>>; + !state => state; + return this; + } +} + +class NthToggle extends Toggle { + int count, countMax; + fun Toggle activate() { + if(++count >= countMax) { + (this $ Toggle).activate(); + 0 => count; + } + return this; + } +} + +100000 => int n; + +1 => n; + + +Toggle toggle; +true => int val => toggle.state; + +//repeat(n) { +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +// toggle.activate().value() => val; +//} + +<<>>; + +NthToggle ntoggle; +<< val => ntoggle.state>>>; +3 => ntoggle.countMax; + +repeat(n) { + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; +} + +<<>>; + +// +//Toggle @t; +//ntoggle @=> t; +//<<>>; +//<<>>; +//toggle @=> t; +//<<>>; +//<<>>; +<<>>; diff --git a/tests/benchmark/method_call.dart b/tests/benchmark/method_call.dart new file mode 100644 index 00000000..540a8266 --- /dev/null +++ b/tests/benchmark/method_call.dart @@ -0,0 +1,78 @@ +class Toggle { + var _state; + + Toggle(startState) { + _state = startState; + } + + get value => _state; + + activate() { + _state = !_state; + return this; + } +} + +class NthToggle extends Toggle { + var _count; + var _countMax; + + NthToggle(startState, maxCounter) + : super(startState) { + _countMax = maxCounter; + _count = 0; + } + + activate() { + _count = _count + 1; + if (_count >= _countMax) { + super.activate(); + _count = 0; + } + + return this; + } +} + +main() { + Stopwatch watch = new Stopwatch(); + watch.start(); + + var n = 100000; + var val = true; + var toggle = new Toggle(val); + + for (var i = 0; i < n; i++) { + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + val = toggle.activate().value; + } + + print(toggle.value); + + val = true; + var ntoggle = new NthToggle(val, 3); + + for (var i = 0; i < n; i++) { + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + val = ntoggle.activate().value; + } + + print(ntoggle.value); + print("elapsed: ${watch.elapsedMilliseconds / 1000}"); +} diff --git a/tests/benchmark/method_call.gw b/tests/benchmark/method_call.gw new file mode 100644 index 00000000..76073d3c --- /dev/null +++ b/tests/benchmark/method_call.gw @@ -0,0 +1,58 @@ +class Toggle { + bool state; + fun bool value() { return state; } + fun Toggle activate() { + !state => state; + return this; + } +} + +class NthToggle extends Toggle { + int count, countMax; + fun Toggle activate() { + if(++count >= countMax) { + (this $ Toggle).activate(); + 0 => count; + } + return this; + } +} + +100000 => int n; + +Toggle toggle; +true => bool val => toggle.state; + +repeat(n) { + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; + toggle.activate().value() => val; +} + +<<>>; + +NthToggle ntoggle; +true => val => ntoggle.state; +3 => ntoggle.countMax; + +repeat(n) { + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; + ntoggle.activate().value() => val; +} + +<<>>; diff --git a/tests/benchmark/method_call.lua b/tests/benchmark/method_call.lua new file mode 100644 index 00000000..45ce5357 --- /dev/null +++ b/tests/benchmark/method_call.lua @@ -0,0 +1,94 @@ +-- $Id: methcall.lua,v 1.2 2004-06-12 16:19:43 bfulgham Exp $ +-- http://shootout.alioth.debian.org +-- contributed by Roberto Ierusalimschy + +-------------------------------------------------------------- +-- Toggle class +-------------------------------------------------------------- + +Toggle = {} + +function Toggle:value () + return self.state +end + +function Toggle:activate () + self.state = not self.state + return self +end + +function Toggle:new (start_state) + local o = {state = start_state} + self.__index =self + setmetatable(o, self) + return o +end + + +-------------------------------------------------------------- +-- NthToggle class +-------------------------------------------------------------- + +NthToggle = Toggle:new() + +function NthToggle:activate () + self.counter = self.counter + 1 + if self.counter >= self.count_max then + Toggle.activate(self) + self.counter = 0 + end + return self +end + +function NthToggle:new (start_state, max_counter) + local o = Toggle.new(self, start_state) + o.count_max = max_counter + o.counter = 0 + return o +end + + +----------------------------------------------------------- +-- main +----------------------------------------------------------- + +function main () + local start = os.clock() + local N = 100000 + + local val = 1 + local toggle = Toggle:new(val) + for i=1,N do + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + val = toggle:activate():value() + end + print(val and "true" or "false") + + val = 1 + local ntoggle = NthToggle:new(val, 3) + for i=1,N do + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + val = ntoggle:activate():value() + end + print(val and "true" or "false") + io.write(string.format("elapsed: %.8f\n", os.clock() - start)) +end + +main() + diff --git a/tests/benchmark/method_call.py b/tests/benchmark/method_call.py new file mode 100644 index 00000000..17af5599 --- /dev/null +++ b/tests/benchmark/method_call.py @@ -0,0 +1,80 @@ +#!/usr/bin/python +# http://www.bagley.org/~doug/shootout/ +from __future__ import print_function + +import sys +import time + +# Map "range" to an efficient range in both Python 2 and 3. +try: + range = xrange +except NameError: + pass + +class Toggle(object): + def __init__(self, start_state): + self.bool = start_state + def value(self): + return(self.bool) + def activate(self): + self.bool = not self.bool + return(self) + +class NthToggle(Toggle): + def __init__(self, start_state, max_counter): + Toggle.__init__(self, start_state) + self.count_max = max_counter + self.counter = 0 + def activate(self): + self.counter += 1 + if (self.counter >= self.count_max): + super(NthToggle, self).activate() + self.counter = 0 + return(self) + + +def main(): + start = time.clock() + + NUM = 100000 + + val = 1 + toggle = Toggle(val) + for i in range(0,NUM): + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + if val: + print("true") + else: + print("false") + + val = 1 + ntoggle = NthToggle(val, 3) + for i in range(0,NUM): + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + if val: + print("true") + else: + print("false") + + print("elapsed: " + str(time.clock() - start)) + + +main() diff --git a/tests/benchmark/method_call.rb b/tests/benchmark/method_call.rb new file mode 100644 index 00000000..40611589 --- /dev/null +++ b/tests/benchmark/method_call.rb @@ -0,0 +1,79 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: methcall.ruby,v 1.1 2004-05-19 18:10:41 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ +# with help from Aristarkh Zagorodnikov + +class Toggle + def initialize(start_state) + @bool = start_state + end + + def value + @bool + end + + def activate + @bool = !@bool + self + end +end + +class NthToggle < Toggle + def initialize(start_state, max_counter) + super start_state + @count_max = max_counter + @counter = 0 + end + + def activate + @counter += 1 + if @counter >= @count_max + super + @counter = 0 + end + self + end +end + +def main() + start = Time.now + + n = 100000 + + val = 1 + toggle = Toggle.new(val) + n.times do + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + val = toggle.activate().value() + end + if val then puts "true" else puts "false" end + + val = 1 + ntoggle = NthToggle.new(val, 3) + n.times do + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + val = ntoggle.activate().value() + end + if val then puts "true" else puts "false" end + + puts "elapsed: " + (Time.now - start).to_s +end + +main() diff --git a/tests/benchmark/method_call.wren b/tests/benchmark/method_call.wren new file mode 100644 index 00000000..93367cb7 --- /dev/null +++ b/tests/benchmark/method_call.wren @@ -0,0 +1,68 @@ +class Toggle { + construct new(startState) { + _state = startState + } + + value { _state } + activate { + _state = !_state + return this + } +} + +class NthToggle is Toggle { + construct new(startState, maxCounter) { + super(startState) + _countMax = maxCounter + _count = 0 + } + + activate { + _count = _count + 1 + if (_count >= _countMax) { + super.activate + _count = 0 + } + + return this + } +} + +var start = System.clock +var n = 100000 +var val = true +var toggle = Toggle.new(val) + +for (i in 0...n) { + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value + val = toggle.activate.value +} + +System.print(toggle.value) + +val = true +var ntoggle = NthToggle.new(val, 3) + +for (i in 0...n) { + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value + val = ntoggle.activate.value +} + +System.print(ntoggle.value) +System.print("elapsed: %(System.clock - start)")