]> Nishi Git Mirror - gwion.git/commitdiff
:book: Update
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Nov 2019 22:40:31 +0000 (23:40 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sun, 10 Nov 2019 22:40:31 +0000 (23:40 +0100)
79 files changed:
benchmark/binary-trees-gc.wren [new file with mode: 0644]
benchmark/binary-trees.dart [new file with mode: 0644]
benchmark/binary-trees.gw [new file with mode: 0644]
benchmark/binary-trees.lua [new file with mode: 0644]
benchmark/binary-trees.py [new file with mode: 0644]
benchmark/binary-trees.rb [new file with mode: 0644]
benchmark/binary-trees.wren [new file with mode: 0644]
benchmark/fib-recurs.ck [new file with mode: 0644]
benchmark/fib-recurs.gw [new file with mode: 0644]
benchmark/fib-recurs.hs [new file with mode: 0644]
benchmark/fib-recurs.lua [new file with mode: 0644]
benchmark/fib-recurs.pl [new file with mode: 0644]
benchmark/fib-recurs.py [new file with mode: 0644]
benchmark/fib-recurs.rb [new file with mode: 0644]
benchmark/fib-recurs.wren [new file with mode: 0644]
benchmark/fib.dart [new file with mode: 0644]
benchmark/fib.gw [new file with mode: 0644]
benchmark/fib.lua [new file with mode: 0644]
benchmark/fib.py [new file with mode: 0644]
benchmark/fib.rb [new file with mode: 0644]
benchmark/fib.wren [new file with mode: 0644]
benchmark/for.dart [new file with mode: 0644]
benchmark/for.gw [new file with mode: 0644]
benchmark/for.lua [new file with mode: 0644]
benchmark/for.py [new file with mode: 0644]
benchmark/for.rb [new file with mode: 0644]
benchmark/for.wren [new file with mode: 0644]
benchmark/method-call.ck [new file with mode: 0644]
benchmark/method-call.dart [new file with mode: 0644]
benchmark/method-call.gw [new file with mode: 0644]
benchmark/method-call.lua [new file with mode: 0644]
benchmark/method-call.py [new file with mode: 0644]
benchmark/method-call.rb [new file with mode: 0644]
benchmark/method-call.wren [new file with mode: 0644]
benchmark/results/binary-trees.dat [new file with mode: 0644]
benchmark/results/binary-trees.png [new file with mode: 0644]
benchmark/results/fib-recurs.dat [new file with mode: 0644]
benchmark/results/fib-recurs.png [new file with mode: 0644]
benchmark/results/fib.dat [new file with mode: 0644]
benchmark/results/fib.png [new file with mode: 0644]
benchmark/results/for.dat [new file with mode: 0644]
benchmark/results/for.png [new file with mode: 0644]
benchmark/results/method-call.dat [new file with mode: 0644]
benchmark/results/method-call.png [new file with mode: 0644]
benchmark/results/string-equals.dat [new file with mode: 0644]
benchmark/results/string-equals.png [new file with mode: 0644]
benchmark/string-equals.gw [new file with mode: 0644]
benchmark/string-equals.py [new file with mode: 0644]
benchmark/string-equals.wren [new file with mode: 0644]
docs/Benchmarks.mdr
docs/assets/benchmark/Makefile.dat [deleted file]
docs/assets/benchmark/bench.plot.dat [deleted file]
docs/assets/benchmark/benchmark.sh.dat [deleted file]
docs/assets/benchmark/book.toml.dat [deleted file]
docs/assets/benchmark/custom.css.dat [deleted file]
docs/assets/benchmark/docs.dat [deleted file]
docs/assets/benchmark/forloop0.gw.dat [deleted file]
docs/assets/benchmark/forloop2.gw.dat [deleted file]
docs/assets/benchmark/forloop3.gw.dat [deleted file]
docs/assets/benchmark/forloop4.gw.dat [deleted file]
docs/assets/benchmark/forloop5.gw.dat [deleted file]
docs/assets/benchmark/function0.gw.dat [deleted file]
docs/assets/benchmark/helloworld.gw.dat [deleted file]
docs/assets/benchmark/lambda_args0.gw.dat [deleted file]
docs/assets/benchmark/lambda_call0.gw.dat [deleted file]
docs/assets/benchmark/lambda_fptr0.gw.dat [deleted file]
docs/assets/benchmark/log.dat [deleted file]
docs/assets/benchmark/repeat.gw.dat [deleted file]
docs/assets/benchmark/repeat2.gw.dat [deleted file]
docs/assets/benchmark/scripts.dat [deleted file]
docs/assets/benchmark/src.dat [deleted file]
docs/assets/benchmark/variadic.gw.dat [deleted file]
docs/assets/benchmark/while0.gw.dat [deleted file]
docs/assets/benchmark/while1.gw.dat [deleted file]
docs/custom.css [deleted file]
scripts/bench.plot [new file with mode: 0644]
scripts/benchmark.sh [new file with mode: 0644]
scripts/ensure.sh
scripts/test.sh

diff --git a/benchmark/binary-trees-gc.wren b/benchmark/binary-trees-gc.wren
new file mode 100644 (file)
index 0000000..803202e
--- /dev/null
@@ -0,0 +1,55 @@
+// Ported from the Python version.
+
+class Tree {
+  construct new(item, depth) {
+    _item = item
+    if (depth > 0) {
+      var item2 = item + item
+      depth = depth - 1
+      _left = Tree.new(item2 - 1, depth)
+      _right = Tree.new(item2, depth)
+    }
+  }
+
+  check {
+    if (_left == null) {
+      return _item
+    }
+
+    return _item + _left.check - _right.check
+  }
+}
+
+var minDepth = 4
+var maxDepth = 12
+var stretchDepth = maxDepth + 1
+
+System.print("stretch tree of depth %(stretchDepth) check: " +
+    "%(Tree.new(0, stretchDepth).check)")
+for (i in 1...1000) System.gc()
+
+var longLivedTree = Tree.new(0, maxDepth)
+
+// iterations = 2 ** maxDepth
+var iterations = 1
+for (d in 0...maxDepth) {
+  iterations = iterations * 2
+}
+
+var depth = minDepth
+while (depth < stretchDepth) {
+  var check = 0
+  for (i in 1..iterations) {
+    check = check + Tree.new(i, depth).check + Tree.new(-i, depth).check
+  }
+
+  System.print("%(iterations * 2) trees of depth %(depth) check: %(check)")
+  for (i in 1...1000) System.gc()
+
+  iterations = iterations / 4
+  depth = depth + 2
+}
+
+System.print(
+    "long lived tree of depth %(maxDepth) check: %(longLivedTree.check)")
+for (i in 1...1000) System.gc()
diff --git a/benchmark/binary-trees.dart b/benchmark/binary-trees.dart
new file mode 100644 (file)
index 0000000..f7d52d5
--- /dev/null
@@ -0,0 +1,56 @@
+// Ported from the Wren version.
+
+class Tree {
+  var _item;
+  var _left;
+  var _right;
+
+  Tree(item, depth) {
+    _item = item;
+    if (depth > 0) {
+      var item2 = item + item;
+      depth--;
+      _left = new Tree(item2 - 1, depth);
+      _right = new Tree(item2, depth);
+    }
+  }
+
+  get check {
+    if (_left == null) {
+      return _item;
+    }
+
+    return _item + _left.check - _right.check;
+  }
+}
+
+main() {
+  var minDepth = 4;
+  var maxDepth = 12;
+  var stretchDepth = maxDepth + 1;
+
+  print("stretch tree of depth ${stretchDepth} check: "
+      "${new Tree(0, stretchDepth).check}");
+
+  var longLivedTree = new Tree(0, maxDepth);
+
+  // iterations = 2 ** maxDepth
+  var iterations = 1;
+  for (var d = 0; d < maxDepth; d++) {
+    iterations = iterations * 2;
+  }
+
+  var depth = minDepth;
+  while (depth < stretchDepth) {
+    var check = 0;
+    for (var i = 1; i <= iterations; i++) {
+      check += new Tree(i, depth).check + new Tree(-i, depth).check;
+    }
+
+    print("${iterations * 2} trees of depth ${depth} check: ${check}");
+    iterations ~/= 4;
+    depth += 2;
+  }
+
+  print("long lived tree of depth ${maxDepth} check: ${longLivedTree.check}");
+}
diff --git a/benchmark/binary-trees.gw b/benchmark/binary-trees.gw
new file mode 100644 (file)
index 0000000..af3486c
--- /dev/null
@@ -0,0 +1,51 @@
+#! Ported from the Wren version.
+
+class Tree {
+  int item;
+  Tree @left, right;
+
+  fun static Tree new_Tree(int it, int depth) {
+    Tree t;
+    it => t.item;
+    if (depth > 0) {
+      it + it => int item2;
+      --depth;
+      Tree.new_Tree(item2 - 1, depth) @=> t.left;
+      Tree.new_Tree(item2, depth) @=> t.right;
+    }
+    return t;
+  }
+
+  fun int check() {
+    if (!left)
+      return item;
+    return item + left.check() - right.check();
+  }
+}
+
+4 => int minDepth;
+12 => int maxDepth;
+maxDepth + 1 => int stretchDepth;
+
+<<< "stretch tree of depth ", stretchDepth, " check: ",
+  Tree.new_Tree(0, stretchDepth).check() >>>;
+
+Tree.new_Tree(0, maxDepth) @=> Tree@ longLivedTree;
+
+#! iterations = 2 ** maxDepth
+1 => int iterations;
+for (int d; d < maxDepth; ++d)
+  2 *=> iterations;
+
+minDepth => int depth;
+while (depth < stretchDepth) {
+  int check;
+  for (int i; i < iterations; ++i)
+    Tree.new_Tree(i, depth).check() + Tree.new_Tree(-i, depth).check() +=> check;
+
+  <<< iterations * 2, " trees of depth ", depth, " check: ", check >>>;
+  4 /=> iterations;
+  2 +=> depth;
+}
+
+<<< "long lived tree of depth ", maxDepth, " check: ", longLivedTree.check() >>>;
diff --git a/benchmark/binary-trees.lua b/benchmark/binary-trees.lua
new file mode 100644 (file)
index 0000000..e690c27
--- /dev/null
@@ -0,0 +1,50 @@
+-- The Computer Language Benchmarks Game
+-- http://shootout.alioth.debian.org/
+-- contributed by Mike Pall
+
+local function BottomUpTree(item, depth)
+  if depth > 0 then
+    local i = item + item
+    depth = depth - 1
+    local left, right = BottomUpTree(i-1, depth), BottomUpTree(i, depth)
+    return { item, left, right }
+  else
+    return { item }
+  end
+end
+
+local function ItemCheck(tree)
+  if tree[2] then
+    return tree[1] + ItemCheck(tree[2]) - ItemCheck(tree[3])
+  else
+    return tree[1]
+  end
+end
+
+local N = 12
+local mindepth = 4
+local maxdepth = mindepth + 2
+if maxdepth < N then maxdepth = N end
+
+do
+  local stretchdepth = maxdepth + 1
+  local stretchtree = BottomUpTree(0, stretchdepth)
+  io.write(string.format("stretch tree of depth %d check: %d\n",
+    stretchdepth, ItemCheck(stretchtree)))
+end
+
+local longlivedtree = BottomUpTree(0, maxdepth)
+
+for depth=mindepth,maxdepth,2 do
+  local iterations = 2 ^ (maxdepth - depth + mindepth)
+  local check = 0
+  for i=1,iterations do
+    check = check + ItemCheck(BottomUpTree(1, depth)) +
+            ItemCheck(BottomUpTree(-1, depth))
+  end
+  io.write(string.format("%d trees of depth %d check: %d\n",
+    iterations*2, depth, check))
+end
+
+io.write(string.format("long lived tree of depth %d check: %d\n",
+  maxdepth, ItemCheck(longlivedtree)))
diff --git a/benchmark/binary-trees.py b/benchmark/binary-trees.py
new file mode 100644 (file)
index 0000000..b08adf3
--- /dev/null
@@ -0,0 +1,44 @@
+# The Computer Language Benchmarks Game
+# http://shootout.alioth.debian.org/
+#
+# contributed by Antoine Pitrou
+# modified by Dominique Wahli
+# modified by Heinrich Acker
+from __future__ import print_function
+
+# Map "range" to an efficient range in both Python 2 and 3.
+try:
+    range = xrange
+except NameError:
+    pass
+
+def make_tree(item, depth):
+    if not depth: return item, None, None
+    item2 = item + item
+    depth -= 1
+    return item, make_tree(item2 - 1, depth), make_tree(item2, depth)
+
+def check_tree(node):
+    item, left, right = node
+    if not left: return item
+    return item + check_tree(left) - check_tree(right)
+
+min_depth = 4
+max_depth = 12
+stretch_depth = max_depth + 1
+
+print("stretch tree of depth %d check:" % stretch_depth, check_tree(make_tree(0, stretch_depth)))
+
+long_lived_tree = make_tree(0, max_depth)
+
+iterations = 2 ** max_depth
+for depth in range(min_depth, stretch_depth, 2):
+
+    check = 0
+    for i in range(1, iterations + 1):
+        check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth))
+
+    print("%d trees of depth %d check:" % (iterations * 2, depth), check)
+    iterations //= 4
+
+print("long lived tree of depth %d check:" % max_depth, check_tree(long_lived_tree))
diff --git a/benchmark/binary-trees.rb b/benchmark/binary-trees.rb
new file mode 100644 (file)
index 0000000..2118083
--- /dev/null
@@ -0,0 +1,49 @@
+# The Computer Language Shootout Benchmarks
+# http://shootout.alioth.debian.org
+#
+# contributed by Jesse Millikan
+# Modified by Wesley Moxam
+
+
+def item_check(left, item, right)
+  return item if left.nil?
+  item + item_check(*left) - item_check(*right)
+end
+
+def bottom_up_tree(item, depth)
+  return [nil, item, nil] unless depth > 0
+  item_item = 2 * item
+  depth -= 1
+  [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
+end
+
+max_depth = 12
+min_depth = 4
+
+max_depth = min_depth + 2 if min_depth + 2 > max_depth
+
+stretch_depth = max_depth + 1
+stretch_tree = bottom_up_tree(0, stretch_depth)
+
+puts "stretch tree of depth #{stretch_depth} check: #{item_check(*stretch_tree)}"
+stretch_tree = nil
+
+long_lived_tree = bottom_up_tree(0, max_depth)
+
+min_depth.step(max_depth + 1, 2) do |depth|
+  iterations = 2**(max_depth - depth + min_depth)
+
+  check = 0
+
+  for i in 1..iterations
+    temp_tree = bottom_up_tree(i, depth)
+    check += item_check(*temp_tree)
+
+    temp_tree = bottom_up_tree(-i, depth)
+    check += item_check(*temp_tree)
+  end
+
+  puts "#{iterations * 2} trees of depth #{depth} check: #{check}"
+end
+
+puts "long lived tree of depth #{max_depth} check: #{item_check(*long_lived_tree)}"
diff --git a/benchmark/binary-trees.wren b/benchmark/binary-trees.wren
new file mode 100644 (file)
index 0000000..2393462
--- /dev/null
@@ -0,0 +1,51 @@
+// Ported from the Python version.
+
+class Tree {
+  construct new(item, depth) {
+    _item = item
+    if (depth > 0) {
+      var item2 = item + item
+      depth = depth - 1
+      _left = Tree.new(item2 - 1, depth)
+      _right = Tree.new(item2, depth)
+    }
+  }
+
+  check {
+    if (_left == null) {
+      return _item
+    }
+
+    return _item + _left.check - _right.check
+  }
+}
+
+var minDepth = 4
+var maxDepth = 12
+var stretchDepth = maxDepth + 1
+
+System.print("stretch tree of depth %(stretchDepth) check: " +
+    "%(Tree.new(0, stretchDepth).check)")
+
+var longLivedTree = Tree.new(0, maxDepth)
+
+// iterations = 2 ** maxDepth
+var iterations = 1
+for (d in 0...maxDepth) {
+  iterations = iterations * 2
+}
+
+var depth = minDepth
+while (depth < stretchDepth) {
+  var check = 0
+  for (i in 1..iterations) {
+    check = check + Tree.new(i, depth).check + Tree.new(-i, depth).check
+  }
+
+  System.print("%(iterations * 2) trees of depth %(depth) check: %(check)")
+  iterations = iterations / 4
+  depth = depth + 2
+}
+
+System.print(
+    "long lived tree of depth %(maxDepth) check: %(longLivedTree.check)")
diff --git a/benchmark/fib-recurs.ck b/benchmark/fib-recurs.ck
new file mode 100644 (file)
index 0000000..c0026c4
--- /dev/null
@@ -0,0 +1,10 @@
+//int count = 0;
+fun int recursive_fib(int n)
+{
+//    ++count;
+    if (n < 2)
+        return n;
+    else
+        return recursive_fib(n - 2) + recursive_fib(n - 1);
+}
+<<<recursive_fib(40)>>>;
diff --git a/benchmark/fib-recurs.gw b/benchmark/fib-recurs.gw
new file mode 100644 (file)
index 0000000..be2c4ab
--- /dev/null
@@ -0,0 +1,8 @@
+fun int recursive_fib(int n) {
+    if (n < 2)
+        return n;
+    else
+        return recursive_fib(n - 2) + recursive_fib(n - 1);
+}
+#!<<< 5 => recursive_fib >>>;
+<<< 40 => recursive_fib >>>;
diff --git a/benchmark/fib-recurs.hs b/benchmark/fib-recurs.hs
new file mode 100644 (file)
index 0000000..6929769
--- /dev/null
@@ -0,0 +1,6 @@
+fib :: Int -> Int
+fib n
+  | n < 2 = n
+  | otherwise = (fib (n-2)) + (fib (n-1))
+
+main = print $ fib 40
diff --git a/benchmark/fib-recurs.lua b/benchmark/fib-recurs.lua
new file mode 100644 (file)
index 0000000..3b84ea3
--- /dev/null
@@ -0,0 +1,6 @@
+local function fib(n)
+    if n <= 2 then return 1 end
+    return fib(n - 1) + fib(n - 2)
+end
+
+print(fib(40))
diff --git a/benchmark/fib-recurs.pl b/benchmark/fib-recurs.pl
new file mode 100644 (file)
index 0000000..55092d2
--- /dev/null
@@ -0,0 +1,9 @@
+sub fibonacci_recurs {
+   my ($number) = @_;
+   if ($number < 2) { # base case
+      return $number;
+   }
+   return fibonacci_recurs($number-1) + fibonacci_recurs($number-2);
+}
+
+print fibonacci_recurs(40) , "\n";
diff --git a/benchmark/fib-recurs.py b/benchmark/fib-recurs.py
new file mode 100644 (file)
index 0000000..672317f
--- /dev/null
@@ -0,0 +1,7 @@
+def fibonacci_recurs(n):
+  if n < 2:
+    return n;
+  else:
+    return (fibonacci_recurs(n-1) + fibonacci_recurs(n-2))
+
+print(fibonacci_recurs(40))
diff --git a/benchmark/fib-recurs.rb b/benchmark/fib-recurs.rb
new file mode 100644 (file)
index 0000000..00f33f1
--- /dev/null
@@ -0,0 +1,5 @@
+def fibonacci_recurs( n )
+  if n < 2 then return n end
+  return ( fibonacci_recurs( n - 1 ) + fibonacci_recurs( n - 2 ) )
+end
+puts fibonacci_recurs(40)
diff --git a/benchmark/fib-recurs.wren b/benchmark/fib-recurs.wren
new file mode 100644 (file)
index 0000000..db980c4
--- /dev/null
@@ -0,0 +1,8 @@
+class Fib {
+  static get(n) {
+    if (n < 2) return n
+    return get(n - 1) + get(n - 2)
+  }
+}
+
+System.print(Fib.get(40))
diff --git a/benchmark/fib.dart b/benchmark/fib.dart
new file mode 100644 (file)
index 0000000..3ffa670
--- /dev/null
@@ -0,0 +1,10 @@
+fib(n) {
+  if (n < 2) return n;
+  return fib(n - 1) + fib(n - 2);
+}
+
+main() {
+  for (var i = 0; i < 5; i++) {
+    print(fib(28));
+  }
+}
diff --git a/benchmark/fib.gw b/benchmark/fib.gw
new file mode 100644 (file)
index 0000000..19f56b9
--- /dev/null
@@ -0,0 +1,8 @@
+class Fib {
+  fun static int get(int n) {
+    if (n < 2) return n;
+    return get(n - 1) + get(n - 2);
+  }
+}
+repeat(5)
+  <<< Fib.get(28) >>>;
diff --git a/benchmark/fib.lua b/benchmark/fib.lua
new file mode 100644 (file)
index 0000000..a4f06e7
--- /dev/null
@@ -0,0 +1,8 @@
+function fib(n)
+  if n < 2 then return n end
+  return fib(n - 2) + fib(n - 1)
+end
+
+for i = 1, 5 do
+  io.write(fib(28) .. "\n")
+end
diff --git a/benchmark/fib.py b/benchmark/fib.py
new file mode 100644 (file)
index 0000000..c2f3ba4
--- /dev/null
@@ -0,0 +1,8 @@
+from __future__ import print_function
+
+def fib(n):
+  if n < 2: return n
+  return fib(n - 1) + fib(n - 2)
+
+for i in range(0, 5):
+  print(fib(28))
diff --git a/benchmark/fib.rb b/benchmark/fib.rb
new file mode 100644 (file)
index 0000000..c496913
--- /dev/null
@@ -0,0 +1,11 @@
+def fib(n)
+  if n < 2 then
+    n
+  else
+    fib(n - 1) + fib(n - 2)
+  end
+end
+
+for i in 0...5
+  puts fib(28)
+end
diff --git a/benchmark/fib.wren b/benchmark/fib.wren
new file mode 100644 (file)
index 0000000..441a7e6
--- /dev/null
@@ -0,0 +1,10 @@
+class Fib {
+  static get(n) {
+    if (n < 2) return n
+    return get(n - 1) + get(n - 2)
+  }
+}
+
+for (i in 1..5) {
+  System.print(Fib.get(28))
+}
diff --git a/benchmark/for.dart b/benchmark/for.dart
new file mode 100644 (file)
index 0000000..14aadbd
--- /dev/null
@@ -0,0 +1,10 @@
+main() {
+  var list = [];
+
+  for (var i = 0; i < 1000000; i++) list.add(i);
+
+  var sum = 0;
+  for (i in list) sum += i;
+
+  print(sum);
+}
diff --git a/benchmark/for.gw b/benchmark/for.gw
new file mode 100644 (file)
index 0000000..6ec6aaa
--- /dev/null
@@ -0,0 +1,10 @@
+int list[0];
+
+for (int i; i < 1000000; ++i)
+ list << i;
+
+int sum;
+for(auto i : list)
+  i +=> sum;
+
+<<< sum >>>;
diff --git a/benchmark/for.lua b/benchmark/for.lua
new file mode 100644 (file)
index 0000000..b03654b
--- /dev/null
@@ -0,0 +1,10 @@
+local list = {}
+for i = 0, 999999 do
+  list[i] = i
+end
+
+local sum = 0
+for k, i in pairs(list) do
+  sum = sum + i
+end
+io.write(sum .. "\n")
diff --git a/benchmark/for.py b/benchmark/for.py
new file mode 100644 (file)
index 0000000..cf31dda
--- /dev/null
@@ -0,0 +1,16 @@
+from __future__ import print_function
+
+# Map "range" to an efficient range in both Python 2 and 3.
+try:
+    range = xrange
+except NameError:
+    pass
+
+list = []
+for i in range(0, 1000000):
+  list.append(i)
+
+sum = 0
+for i in list:
+  sum += i
+print(sum)
diff --git a/benchmark/for.rb b/benchmark/for.rb
new file mode 100644 (file)
index 0000000..87b9d79
--- /dev/null
@@ -0,0 +1,6 @@
+list = []
+1000000.times {|i| list << i}
+
+sum = 0
+list.each {|i| sum += i}
+puts sum
diff --git a/benchmark/for.wren b/benchmark/for.wren
new file mode 100644 (file)
index 0000000..ef25978
--- /dev/null
@@ -0,0 +1,8 @@
+var list = []
+
+for (i in 0...1000000) list.add(i)
+
+var sum = 0
+for (i in list) sum = sum + i
+
+System.print(sum)
diff --git a/benchmark/method-call.ck b/benchmark/method-call.ck
new file mode 100644 (file)
index 0000000..5e09599
--- /dev/null
@@ -0,0 +1,58 @@
+class Toggle {
+  int state;
+  fun int 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 => 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;
+}
+
+<<< toggle.value() >>>;
+
+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;
+}
+
+<<< ntoggle.value() >>>;
diff --git a/benchmark/method-call.dart b/benchmark/method-call.dart
new file mode 100644 (file)
index 0000000..540a826
--- /dev/null
@@ -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/benchmark/method-call.gw b/benchmark/method-call.gw
new file mode 100644 (file)
index 0000000..5a17f90
--- /dev/null
@@ -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;
+}
+
+<<< toggle.value() >>>;
+
+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;
+}
+
+<<< ntoggle.value() >>>;
diff --git a/benchmark/method-call.lua b/benchmark/method-call.lua
new file mode 100644 (file)
index 0000000..20a6d6a
--- /dev/null
@@ -0,0 +1,92 @@
+-- $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 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")
+end
+
+main()
+
diff --git a/benchmark/method-call.py b/benchmark/method-call.py
new file mode 100644 (file)
index 0000000..c307a89
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+# http://www.bagley.org/~doug/shootout/
+from __future__ import print_function
+
+# 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():
+    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")
+
+main()
diff --git a/benchmark/method-call.rb b/benchmark/method-call.rb
new file mode 100644 (file)
index 0000000..4061158
--- /dev/null
@@ -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/benchmark/method-call.wren b/benchmark/method-call.wren
new file mode 100644 (file)
index 0000000..93367cb
--- /dev/null
@@ -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)")
diff --git a/benchmark/results/binary-trees.dat b/benchmark/results/binary-trees.dat
new file mode 100644 (file)
index 0000000..de0dc5d
--- /dev/null
@@ -0,0 +1,3 @@
+gwion Fichier binaire (entrée standard) correspondant
+wren 0.205150 0.31
+lua 0.29314 0.64
diff --git a/benchmark/results/binary-trees.png b/benchmark/results/binary-trees.png
new file mode 100644 (file)
index 0000000..423552e
Binary files /dev/null and b/benchmark/results/binary-trees.png differ
diff --git a/benchmark/results/fib-recurs.dat b/benchmark/results/fib-recurs.dat
new file mode 100644 (file)
index 0000000..d6a2332
--- /dev/null
@@ -0,0 +1,3 @@
+gwion 5.5826 0.47
+wren 13.1697 0.08
+lua 7.10224 0.03
diff --git a/benchmark/results/fib-recurs.png b/benchmark/results/fib-recurs.png
new file mode 100644 (file)
index 0000000..0d7027c
Binary files /dev/null and b/benchmark/results/fib-recurs.png differ
diff --git a/benchmark/results/fib.dat b/benchmark/results/fib.dat
new file mode 100644 (file)
index 0000000..f99749f
--- /dev/null
@@ -0,0 +1,3 @@
+gwion 0.089472 0.30
+wren 0.207495 0.23
+lua 0.20757 0.52
diff --git a/benchmark/results/fib.png b/benchmark/results/fib.png
new file mode 100644 (file)
index 0000000..9c9827f
Binary files /dev/null and b/benchmark/results/fib.png differ
diff --git a/benchmark/results/for.dat b/benchmark/results/for.dat
new file mode 100644 (file)
index 0000000..231d793
--- /dev/null
@@ -0,0 +1,3 @@
+gwion 0.037553 0.50
+wren 0.079285 0.47
+lua 0.049167 0.47
diff --git a/benchmark/results/for.png b/benchmark/results/for.png
new file mode 100644 (file)
index 0000000..3d5bc34
Binary files /dev/null and b/benchmark/results/for.png differ
diff --git a/benchmark/results/method-call.dat b/benchmark/results/method-call.dat
new file mode 100644 (file)
index 0000000..49361a5
--- /dev/null
@@ -0,0 +1,3 @@
+gwion Fichier binaire (entrée standard) correspondant
+wren 0.104943 0.63
+lua 0.24904 1.12
diff --git a/benchmark/results/method-call.png b/benchmark/results/method-call.png
new file mode 100644 (file)
index 0000000..edd83f4
Binary files /dev/null and b/benchmark/results/method-call.png differ
diff --git a/benchmark/results/string-equals.dat b/benchmark/results/string-equals.dat
new file mode 100644 (file)
index 0000000..2814530
--- /dev/null
@@ -0,0 +1,2 @@
+gwion 0.162820 0.19
+wren 0.176206 0.17
diff --git a/benchmark/results/string-equals.png b/benchmark/results/string-equals.png
new file mode 100644 (file)
index 0000000..b0130de
Binary files /dev/null and b/benchmark/results/string-equals.png differ
diff --git a/benchmark/string-equals.gw b/benchmark/string-equals.gw
new file mode 100644 (file)
index 0000000..6dfa7e6
--- /dev/null
@@ -0,0 +1,21 @@
+int count;
+for (int i; i < 1000000; ++i) {
+  if ("abc" == "abc") ++count;
+  if ("a slightly longer string" ==
+      "a slightly longer string") ++count;
+  if ("a significantly longer string but still not overwhelmingly long string" ==
+      "a significantly longer string but still not overwhelmingly long string") ++count;
+
+  if ("" == "abc") ++count;
+  if ("abc" == "abcd") ++count;
+  if ("changed one character" == "changed !ne character") ++count;
+#!  if ("123" == 123) ++count
+  if ("a slightly longer string" ==
+      "a slightly longer string!") ++count;
+  if ("a slightly longer string" ==
+      "a slightly longer strinh") ++count;
+  if ("a significantly longer string but still not overwhelmingly long string" ==
+      "another") ++count;
+}
+
+<<< count >>>;
diff --git a/benchmark/string-equals.py b/benchmark/string-equals.py
new file mode 100644 (file)
index 0000000..8829b5c
--- /dev/null
@@ -0,0 +1,35 @@
+from __future__ import print_function
+
+import time
+start = time.clock()
+
+count = 0
+for i in range(0, 1000000):
+  if "abc" == "abc":
+    count = count + 1
+  if "a slightly longer string" == \
+     "a slightly longer string":
+      count = count + 1
+  if "a significantly longer string but still not overwhelmingly long string" == \
+     "a significantly longer string but still not overwhelmingly long string":
+      count = count + 1
+
+  if "" == "abc":
+    count = count + 1
+  if "abc" == "abcd":
+    count = count + 1
+  if "changed one character" == "changed !ne character":
+    count = count + 1
+  if "123" == 123: count = count + 1
+  if "a slightly longer string" == \
+     "a slightly longer string!":
+      count = count + 1
+  if "a slightly longer string" == \
+     "a slightly longer strinh":
+      count = count + 1
+  if "a significantly longer string but still not overwhelmingly long string" == \
+     "another":
+      count = count + 1
+
+print(count)
+print("elapsed: " + str(time.clock() - start))
diff --git a/benchmark/string-equals.wren b/benchmark/string-equals.wren
new file mode 100644 (file)
index 0000000..0c87bcc
--- /dev/null
@@ -0,0 +1,24 @@
+var start = System.clock
+
+var count = 0
+for (i in 1..1000000) {
+  if ("abc" == "abc") count = count + 1
+  if ("a slightly longer string" ==
+      "a slightly longer string") count = count + 1
+  if ("a significantly longer string but still not overwhelmingly long string" ==
+      "a significantly longer string but still not overwhelmingly long string") count = count + 1
+
+  if ("" == "abc") count = count + 1
+  if ("abc" == "abcd") count = count + 1
+  if ("changed one character" == "changed !ne character") count = count + 1
+  if ("123" == 123) count = count + 1
+  if ("a slightly longer string" ==
+      "a slightly longer string!") count = count + 1
+  if ("a slightly longer string" ==
+      "a slightly longer strinh") count = count + 1
+  if ("a significantly longer string but still not overwhelmingly long string" ==
+      "another") count = count + 1
+}
+
+System.print(count)
+System.print("elapsed: %(System.clock - start)")
index 34a60725b851eca95b7053570caf6eb2b06d220d..39a2e8cf55034452d6ae5b5fc4b783f3745e578e 100644 (file)
@@ -1,89 +1,3 @@
 # Benchmarks
 
-We'll need a bash script
-
-<link rel=styleSheet href="../assets/doc.css" TYPE="text/css"><div id="org-categories"><ul class="lev1"><li><a href="#">Show the code</a></li><ul class="lev2"><a href="#">
-@``` benchmark.sh
-#!/bin/sh
-language=("gwion" "wren" "lua")
-extension=("gw" "wren" "lua")
-test_dir="tests/benchmark"
-plot_script="bench.plot"
-: "${repeats:=10}"
-
-run() {
-  perf stat -r"$repeats" "$1" "$test_dir/$3.$2" 2>&1 | grep "time elapsed" |
-    sed 's/ *\([0-9]*\),\([0-9]*\) .* seconds time elapsed *( +- *\([0-9]*\),\([0-9]*\)% )/\1.\2 \3.\4/'
-}
-
-get_list() {
-  for file in $test_dir/*.gw
-  do basename "$file" .gw
-  done
-}
-
-get_test() {
-  for (( i=0; i<=$(( ${#language[@]} -1 )); i++ ))
-  do
-    if [ -f "$test_dir/$1.${extension[$i]}" ]
-    then echo "${language[$i]} $(run "${language[$i]}" "${extension[$i]}" "$1")"
-    fi
-  done > "docs/assets/benchmark/$1.dat"
-}
-
-plot() {
-  gnuplot -e "bench='$1'" "$plot_script"
-}
-
-for bench in $(get_list)
-do
-echo $bench
-  get_test "$bench"
-  plot "$bench"
-  echo "### $bench"
-  echo '<link rel=styleSheet href="../assets/doc.css" TYPE="text/css"><div id="org-categories"><ul class="lev1"><li><a href="#">Show the code</a></li><ul class="lev2"><a href="#">'
-  echo "\`\`\`"
-  cat "$test_dir/$bench.gw"
-  echo "\`\`\`"
-  echo '</a></a></li></ul></ul></div>'
-  echo "![](assets/benchmark/$bench.png)"
-done
-@```  
-</a></a></li></ul></ul></div>
-
-### and a gnuplot script
-
-<link rel=styleSheet href="../assets/doc.css" TYPE="text/css"><div id="org-categories"><ul class="lev1"><li><a href="#">Show the code</a></li><ul class="lev2"><a href="#">
-@``` bench.plot
-set terminal png truecolor
-
-#if (!exists("bench"))
-#  bench = 'bench'
-if (!exists("test_dir"))
-  test_dir = 'tests/benchmark'
-
-dat_name = sprintf("docs/assets/benchmark/%s.dat", bench)
-
-stats dat_name using 0:2 noout
-max = STATS_max_y+(0.1*STATS_max_y)
-
-set title bench
-set output sprintf("docs/assets/benchmark/%s.png", bench)
-set xrange [-0.5:((ceil(STATS_max_x))+0.5)]
-set yrange [0:max]
-set boxwidth 0.50
-set nokey
-set xtics nomirror
-set ytics nomirror
-
-set style fill transparent solid 0.25 # partial transparency
-set style fill noborder # no separate top/bottom lines
-
-plot dat_name using 0:2:($2*($3/100.0)):xtic(2) with boxerrorbar lc "blue" notitle, \
-  '' using 0:(max-(0.05*max)):1 with labels
-@```  
-</a></a></li></ul></ul></div>
-
-## Show the results
-Then just run it
-@exec bash benchmark.sh; rm bench.plot benchmark.sh
+@exec for a in benchmark_results/*.png; do echo "![${a:-4}]($a \"${a:-4}\")"; done
diff --git a/docs/assets/benchmark/Makefile.dat b/docs/assets/benchmark/Makefile.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/bench.plot.dat b/docs/assets/benchmark/bench.plot.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/benchmark.sh.dat b/docs/assets/benchmark/benchmark.sh.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/book.toml.dat b/docs/assets/benchmark/book.toml.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/custom.css.dat b/docs/assets/benchmark/custom.css.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/docs.dat b/docs/assets/benchmark/docs.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/forloop0.gw.dat b/docs/assets/benchmark/forloop0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/forloop2.gw.dat b/docs/assets/benchmark/forloop2.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/forloop3.gw.dat b/docs/assets/benchmark/forloop3.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/forloop4.gw.dat b/docs/assets/benchmark/forloop4.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/forloop5.gw.dat b/docs/assets/benchmark/forloop5.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/function0.gw.dat b/docs/assets/benchmark/function0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/helloworld.gw.dat b/docs/assets/benchmark/helloworld.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/lambda_args0.gw.dat b/docs/assets/benchmark/lambda_args0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/lambda_call0.gw.dat b/docs/assets/benchmark/lambda_call0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/lambda_fptr0.gw.dat b/docs/assets/benchmark/lambda_fptr0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/log.dat b/docs/assets/benchmark/log.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/repeat.gw.dat b/docs/assets/benchmark/repeat.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/repeat2.gw.dat b/docs/assets/benchmark/repeat2.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/scripts.dat b/docs/assets/benchmark/scripts.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/src.dat b/docs/assets/benchmark/src.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/variadic.gw.dat b/docs/assets/benchmark/variadic.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/while0.gw.dat b/docs/assets/benchmark/while0.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/assets/benchmark/while1.gw.dat b/docs/assets/benchmark/while1.gw.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/docs/custom.css b/docs/custom.css
deleted file mode 100644 (file)
index c143cd4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-.mdr {
-
-
-}
-
-footer {
-  text-align: center;
-  font-size: small;
-  font-style: italic;
-}
diff --git a/scripts/bench.plot b/scripts/bench.plot
new file mode 100644 (file)
index 0000000..8c81271
--- /dev/null
@@ -0,0 +1,26 @@
+set terminal png truecolor
+
+#if (!exists("bench"))
+#  bench = 'bench'
+if (!exists("test_dir"))
+  test_dir = 'tests/benchmark'
+
+dat_name = sprintf("benchmark/results/%s.dat", bench)
+
+stats dat_name using 0:2 noout
+max = STATS_max_y+(0.1*STATS_max_y)
+
+set title bench
+set output sprintf("benchmark/results/%s.png", bench)
+set xrange [-0.5:((ceil(STATS_max_x))+0.5)]
+set yrange [0:max]
+set boxwidth 0.50
+set nokey
+set xtics nomirror
+set ytics nomirror
+
+set style fill transparent solid 0.25 # partial transparency
+set style fill noborder # no separate top/bottom lines
+
+plot dat_name using 0:2:($2*($3/100.0)):xtic(2) with boxerrorbar lc "blue" notitle, \
+  '' using 0:(max-(0.05*max)):1 with labels
diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh
new file mode 100644 (file)
index 0000000..4a13391
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+language=("gwion" "wren" "lua")
+extension=("gw" "wren" "lua")
+test_dir="benchmark"
+plot_script="scripts/bench.plot"
+: "${repeats:=10}"
+
+run() {
+  perf stat -r"$repeats" "$1" "$test_dir/$3.$2" 2>&1 | grep "time elapsed" |
+    sed 's/ *\([0-9]*\),\([0-9]*\) .* seconds time elapsed *( +- *\([0-9]*\),\([0-9]*\)% )/\1.\2 \3.\4/'
+}
+
+get_list() {
+  for file in $test_dir/*.gw
+  do basename "$file" .gw
+  done
+}
+
+get_test() {
+  for (( i=0; i<=$(( ${#language[@]} -1 )); i++ ))
+  do
+    if [ -f "$test_dir/$1.${extension[$i]}" ]
+    then echo "${language[$i]} $(run "${language[$i]}" "${extension[$i]}" "$1")"
+    fi
+  done > "benchmark/results/$1.dat"
+}
+
+plot() {
+  gnuplot -e "bench='$1'" "$plot_script"
+}
+
+for bench in $(get_list)
+do
+  get_test "$bench"
+  plot "$bench"
+done
index 461e5f8050be345d61a53913f9cebe319176b355..f935c4f3a22863c35ebb5757e52b9030c169c91f 100644 (file)
@@ -34,10 +34,13 @@ footer {
 }
 EOF
 }
-[ -d src ] || sh scripts/mdr2mdbook.sh
-
-[ -f src/SUMMARY.md ] || sh scripts/summary.sh > src/SUMMARY.md
 
 [ -f book.toml ] || toml
 
 [ -f custom.css ] || css
+
+[ -d src ] || sh scripts/mdr2mdbook.sh
+
+[ -f src/SUMMARY.md ] || sh scripts/summary.sh > src/SUMMARY.md
+
+[ -d src/assets ] || cp -r assets src
index 7c92514d6c639f6797b5ba7d88b30b93c1bb04e1..28b75977012d63e9a9060cc6333bed4459c71b0a 100644 (file)
@@ -17,7 +17,7 @@ interm() {
 
 noterm() {
   echo '<p class="mdr">'
-  cat log
+  sed 's/$/<\/br>/' log
   echo "</br>"
   check $@ && printf "${NOTERM_OK}\n" || printf "${NOTERM_NOT_OK}\n"
   echo '</p>'