mlox/benchmark/trees.lox

29 lines
590 B
Lox
Raw Normal View History

2024-08-03 02:44:12 +02:00
class Tree {
init(depth) {
this.depth = depth;
if (depth > 0) {
this.a = Tree(depth - 1);
this.b = Tree(depth - 1);
this.c = Tree(depth - 1);
this.d = Tree(depth - 1);
this.e = Tree(depth - 1);
}
}
walk() {
if (this.depth == 0) return 0;
return this.depth
+ this.a.walk()
+ this.b.walk()
+ this.c.walk()
+ this.d.walk()
+ this.e.walk();
}
}
var tree = Tree(8);
var start = clock();
for (var i = 0; i < 100; i = i + 1) {
if (tree.walk() != 122068) print "Error";
}
print clock() - start;