feat: add binary_trees benchmark suite and fix string escape for tab character
Add Lua, Python, Ruby, and Wren implementations of the binary_trees benchmark from the Computer Language Benchmarks Game. Update the benchmark runner to support multiple benchmarks with output validation, and fix the Wren compiler to handle the '\t' escape sequence in string literals.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# The Computer Language Benchmarks Game
|
||||
# http://shootout.alioth.debian.org/
|
||||
#
|
||||
# contributed by Antoine Pitrou
|
||||
# modified by Dominique Wahli
|
||||
# modified by Heinrich Acker
|
||||
|
||||
import time
|
||||
|
||||
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((item, left, right)):
|
||||
if not left: return item
|
||||
return item + check_tree(left) - check_tree(right)
|
||||
|
||||
min_depth = 4
|
||||
max_depth = max(min_depth + 2, 14)
|
||||
stretch_depth = max_depth + 1
|
||||
|
||||
start = time.clock()
|
||||
print "stretch tree of depth %d\t 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 xrange(min_depth, stretch_depth, 2):
|
||||
|
||||
check = 0
|
||||
for i in xrange(1, iterations + 1):
|
||||
check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth))
|
||||
|
||||
print "%d\t trees of depth %d\t check:" % (iterations * 2, depth), check
|
||||
iterations /= 4
|
||||
|
||||
print "long lived tree of depth %d\t check:" % max_depth, check_tree(long_lived_tree)
|
||||
print("elapsed: " + str(time.clock() - start))
|
||||
Reference in New Issue
Block a user