Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kuroko-lang/master
Add Kuroko to benchmark suite
- Loading branch information
Showing
9 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# The Computer Language Benchmarks Game | ||
# http://shootout.alioth.debian.org/ | ||
# | ||
# contributed by Antoine Pitrou | ||
# modified by Dominique Wahli | ||
# modified by Heinrich Acker | ||
# modified by Kay Lange | ||
|
||
import math | ||
|
||
def make_tree(item, depth): | ||
if not depth: return item, None, None | ||
let item2 = item + item | ||
depth -= 1 | ||
return item, make_tree(item2 - 1, depth), make_tree(item2, depth) | ||
|
||
def check_tree(node): | ||
let item, left, right | ||
item, left, right = node | ||
if not left: return item | ||
return item + check_tree(left) - check_tree(right) | ||
|
||
let min_depth = 4 | ||
let max_depth = 12 | ||
let stretch_depth = max_depth + 1 | ||
|
||
print("stretch tree of depth", stretch_depth, "check:", check_tree(make_tree(0, stretch_depth))) | ||
|
||
let long_lived_tree = make_tree(0, max_depth) | ||
|
||
let iterations = int(2.0 ** max_depth) | ||
for depth = min_depth; depth < stretch_depth; depth += 2: | ||
|
||
let check = 0 | ||
for i in range(1, iterations + 1): | ||
check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth)) | ||
|
||
print(iterations * 2, "trees of depth", depth, "check:", check) | ||
iterations = iterations // 4 | ||
|
||
print("long lived tree of depth", max_depth, "check:", check_tree(long_lived_tree)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def fib(n): | ||
if n < 2: return n | ||
return fib(n - 1) + fib(n - 2) | ||
|
||
for i in range(0, 5): | ||
print(fib(28)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if True: | ||
let l = [] | ||
for i in range(0, 1000000): | ||
l.append(i) | ||
|
||
let s = 0.0 | ||
for i in l: | ||
s += i | ||
print(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/python | ||
# http://www.bagley.org/~doug/shootout/ | ||
|
||
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(): | ||
let NUM = 100000 | ||
|
||
let val = 1 | ||
let 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 | ||
let 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
let 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 "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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters