Created
May 23, 2016 00:13
-
-
Save darach/43fa70cc36c9be308537b3b3a0ea514d to your computer and use it in GitHub Desktop.
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
use "collections" | |
use "time" | |
primitive Factorial | |
""" Factorial | |
""" | |
fun fac(n:U64): U64 => | |
var f : U64 = 1 | |
var i : U64 = 1 | |
if n == 0 then | |
0 | |
else | |
repeat | |
f = f * i | |
i = i + 1 | |
until i <= n end | |
f | |
end | |
actor Blackhole | |
""" This is simply an actor that receives the factorial result | |
""" | |
be receive(n: U64) => | |
None | |
actor FactorialServer | |
""" This approximates the Erlang factorial_server | |
""" | |
let bh : Blackhole = Blackhole | |
be apply(f : U64) => | |
bh.receive(Factorial.fac(f)) | |
actor Main | |
let n : U64 = 10000000 | |
let fac : FactorialServer = FactorialServer | |
new create(env : Env) => | |
let s : U64 = Time.nanos() | |
for i in Range[U64](0,n) do | |
fac(10) | |
end | |
let d = Time.nanos() - s | |
env.out.print("Elapsed: " + d.string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment