Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebalance benchmarks #822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/benchmarks/config_js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ duality_of_compilation/sum_range 1398102
effect_handlers_bench/countdown 16777216
effect_handlers_bench/iterator 22369622
effect_handlers_bench/nqueens 11
effect_handlers_bench/generator 20
effect_handlers_bench/parsing_dollars 7283
effect_handlers_bench/product_early 32768
effect_handlers_bench/resume_nontail 1366
effect_handlers_bench/tree_explore 14
effect_handlers_bench/triples 256
effect_handlers_bench/handler_sieve 1000
2 changes: 2 additions & 0 deletions examples/benchmarks/config_llvm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ duality_of_compilation/sum_range 16777216
effect_handlers_bench/countdown 33554432
effect_handlers_bench/iterator 67108864
effect_handlers_bench/nqueens 12
effect_handlers_bench/generator 25
effect_handlers_bench/parsing_dollars 8192
effect_handlers_bench/product_early 262144
effect_handlers_bench/resume_nontail 65536
effect_handlers_bench/tree_explore 17
effect_handlers_bench/triples 512
effect_handlers_bench/handler_sieve 10000
1 change: 1 addition & 0 deletions examples/benchmarks/effect_handlers_bench/generator.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
57
52 changes: 52 additions & 0 deletions examples/benchmarks/effect_handlers_bench/generator.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import examples/benchmarks/runner

interface Yield {
def yield(x: Int): Unit
}

type Tree {
Leaf();
Node(left: Tree, value: Int, right: Tree)
}

type Generator {
Empty();
Thunk(value: Int, next: () => Generator at {})
}

def make(n: Int): Tree =
if (n == 0) {
Leaf()
} else {
val t = make(n - 1)
Node(t, n, t)
}

def iterate(t: Tree): Unit / Yield =
t match {
case Leaf() => ()
case Node(l, v, r) =>
iterate(l);
do yield(v);
iterate(r)
}

def generate(program: () => Unit / Yield at {}): Generator =
try {
program();
Empty()
} with Yield {
def yield(x) = Thunk(x, fun() { resume(()) })
}

def sum(a: Int, g: Generator): Int =
g match {
case Empty() => a
case Thunk(v, f) => sum(v + a, f())
}

def run(n: Int): Int =
sum(0, generate(fun() { iterate(make(n)) }))

def main() = benchmark(5){run}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17
30 changes: 30 additions & 0 deletions examples/benchmarks/effect_handlers_bench/handler_sieve.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import examples/benchmarks/runner

effect prime(e: Int): Bool

def primes(i: Int, n: Int, a: Int): Int / prime =
if (i >= n) {
a
} else if(do prime(i)) {
try {
primes(i + 1, n, a + i)
} with prime { (e: Int) =>
if (mod(e, i) == 0) {
resume(false)
} else {
resume(do prime(e))
}
}
} else {
primes(i + 1, n, a)
}

def run(n: Int) =
try {
primes(2, n, 0)
} with prime { (e: Int) =>
resume(true)
}

def main() = benchmark(10){run}