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 #8 from Jason2605/feature/dictu
Add Dictu to benchmark suite along with some contributing notes I can't see a flaw 👍 Let's try it
- Loading branch information
Showing
10 changed files
with
215 additions
and
2 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
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,56 @@ | ||
class Tree { | ||
init(item, depth) { | ||
this.item = item; | ||
this.depth = depth; | ||
if (depth > 0) { | ||
const item2 = item + item; | ||
depth = depth - 1; | ||
this.left = Tree(item2 - 1, depth); | ||
this.right = Tree(item2, depth); | ||
} else { | ||
this.left = nil; | ||
this.right = nil; | ||
} | ||
} | ||
|
||
check() { | ||
if (this.left == nil) { | ||
return this.item; | ||
} | ||
|
||
return this.item + this.left.check() - this.right.check(); | ||
} | ||
} | ||
|
||
const minDepth = 4; | ||
const maxDepth = 12; | ||
const stretchDepth = maxDepth + 1; | ||
|
||
const start = System.clock(); | ||
|
||
print("stretch tree of depth: {}".format(stretchDepth)); | ||
|
||
const longLivedTree = Tree(0, maxDepth); | ||
|
||
var iterations = 1; | ||
|
||
for (var d = 0; d < maxDepth; d += 1) { | ||
iterations = iterations * 2; | ||
} | ||
|
||
var depth = minDepth; | ||
while (depth < stretchDepth) { | ||
var check = 0; | ||
var i = 1; | ||
while (i <= iterations) { | ||
check = check + Tree(i, depth).check() + Tree(-i, depth).check(); | ||
i = i + 1; | ||
} | ||
|
||
print("Num trees: {} Depth: {} Check: {} Time: {}".format(iterations * 2, depth, check, System.clock() - start)); | ||
|
||
iterations = iterations / 4; | ||
depth = depth + 2; | ||
} | ||
|
||
print("Long lived tree of depth: {} Check: {}".format(maxDepth, longLivedTree.check())); |
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 @@ | ||
def fibonacci(num) { | ||
if (num < 2) { | ||
return num; | ||
} | ||
|
||
return fibonacci(num - 2) + fibonacci(num - 1); | ||
} | ||
|
||
print(fibonacci(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,12 @@ | ||
def fibonacci(num) { | ||
if (num < 2) { | ||
return num; | ||
} | ||
|
||
return fibonacci(num - 2) + fibonacci(num - 1); | ||
} | ||
|
||
for (var i = 0; i < 5; i += 1) { | ||
print(fibonacci(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,13 @@ | ||
const list = []; | ||
|
||
for (var i = 0; i < 1000000; i += 1) { | ||
list.push(i); | ||
} | ||
|
||
var sum = 0; | ||
|
||
for (var i = 0; i < 1000000; i += 1) { | ||
sum += list[i]; | ||
} | ||
|
||
print(sum); |
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,67 @@ | ||
class Toggle { | ||
init(startState) { | ||
this.state = startState; | ||
} | ||
|
||
value() { return this.state; } | ||
|
||
activate() { | ||
this.state = !this.state; | ||
return this; | ||
} | ||
} | ||
|
||
class NthToggle < Toggle { | ||
init(startState, maxCounter) { | ||
super.init(startState); | ||
this.countMax = maxCounter; | ||
this.count = 0; | ||
} | ||
|
||
activate() { | ||
this.count = this.count + 1; | ||
if (this.count >= this.countMax) { | ||
super.activate(); | ||
this.count = 0; | ||
} | ||
|
||
return this; | ||
} | ||
} | ||
|
||
var val = true; | ||
const n = 100000; | ||
const toggle = Toggle(val); | ||
|
||
for (var i = 0; i < n; i = i + 1) { | ||
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; | ||
const ntoggle = NthToggle(val, 3); | ||
|
||
for (var i = 0; i < n; i = i + 1) { | ||
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()); |
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,35 @@ | ||
var count = 0; | ||
|
||
for (var i = 0; i < 1000000; i += 1) { | ||
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