Skip to content

Commit

Permalink
Add emit test files
Browse files Browse the repository at this point in the history
  • Loading branch information
b-studios committed Jan 22, 2025
1 parent 13bd37c commit ece15c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/benchmarks/other/emit.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
40 changes: 40 additions & 0 deletions examples/benchmarks/other/emit.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import examples/benchmarks/runner

effect emit(value: Double): Unit

def printDoubles { p: () => Unit / emit } =
try { p() } with emit { d =>
println(d)
resume(())
}

def sumDoubles { p: () => Unit / emit } = {
var sum = 0.0
try { p() } with emit { d =>
sum = sum + d
resume(())
}
sum
}

def runningMean { stream: => Unit / emit }: Unit / emit = {
var n = 0
var mean = 0.0
try { stream() }
with emit { x =>
n = n + 1
mean = mean + ((x - mean) / n.toDouble)
do emit(mean)
resume(())
}
}

def generate(N: Int) = {
each(0, N) { n =>
do emit(n.toDouble)
}
}

def run(N: Int) = sumDoubles { runningMean { generate(N) } }.toInt

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

0 comments on commit ece15c7

Please sign in to comment.