type Parking { ready: Channel gate: Channel } syncIdle() (result: Bool) { bench.ready(0) port.blockingPause(config.lifetime()) result = true } idle() () { blocking(bench.ready(0)) bench.pause(config.lifetime()) } asyncIdle() (result: Bool) { idle() result = true } identity(value: Int) (result: Int) { result = value } taskSum(value: Int, state: Int) (result: Int) { job = run(identity(value)) result = state + wait(job) } sum(value: Int, state: Int) (result: Int) { result = state + value } taskSample(index: Int, input: Bytes) () { begin = dever.time.monotonicNanos() checksum = reduce(taskSum, input, 0) end = dever.time.monotonicNanos() blocking(bench.report(begin, end, "tasks", length(input), checksum)) } sendByte(value: Int, output: Channel) () { send(output, value) } produce(input: Bytes, output: Channel) () { each(sendByte, input, output) close(output) } channelSample(index: Int, input: Bytes) () { output = channel(Int, config.channelCapacity()) begin = dever.time.monotonicNanos() producer = run(produce(input, output)) checksum = reduce(sum, stream(output), 0) wait(producer) end = dever.time.monotonicNanos() blocking(bench.report(begin, end, "channels", length(input), checksum)) } waitOne(value: Int, parking: Parking) () { send(parking.ready, value) signaled(receive(parking.gate)) } signaled(value: Int) () {} signaled(value: null) () { blocking(port.reportError("channel closed before expected signal")) } hold(parking: Parking) () { parallelEach(waitOne, config.pendingInput(), config.pending(), parking) } started(value: Int, ready: Channel) () { signaled(receive(ready)) } cancelWorker() () { parking = Parking { ready = channel(Int, config.pending()) gate = channel(Int, 1) } job = run(hold(parking)) each(started, config.pendingInput(), parking.ready) blocking(bench.ready(config.pending())) bench.pause(config.idleSampleMs()) begin = dever.time.monotonicNanos() stop(job) end = dever.time.monotonicNanos() close(parking.ready) close(parking.gate) blocking(bench.report(begin, end, "cancel", config.pending(), config.pending())) } taskWorker() () { input = config.input() blocking(bench.ready(0)) each(taskSample, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], input) } channelWorker() () { input = config.input() blocking(bench.ready(0)) each(channelSample, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], input) } tasks() (result: Bool) { taskWorker() result = true } nestedTaskWorker() () { job = run(taskWorker()) wait(job) } tasksOnWorker() (result: Bool) { nestedTaskWorker() result = true } channels() (result: Bool) { channelWorker() result = true } cancel() (result: Bool) { cancelWorker() result = true }