Created
February 14, 2016 17:08
-
-
Save daxfohl/e613632ab57663825fdb to your computer and use it in GitHub Desktop.
261 ms F# MailboxProcessor impl of https://github.com/atemerev/skynet
This file contains hidden or 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
#time "on" | |
type State = { remaining: int64; aggregate: int64 } | |
let div = 10L | |
let rec skynet num size postback = | |
if size = 1L then | |
postback num | |
else | |
let agent = MailboxProcessor<_>.Start(fun inbox -> | |
let rec loop state = | |
async { | |
let! value = inbox.Receive() | |
if state.remaining = 1L then | |
postback (state.aggregate + value) | |
else | |
return! loop { remaining = state.remaining - 1L; aggregate = state.aggregate + value } | |
} | |
loop { remaining = div; aggregate = 0L }) | |
for i = 0 to 9 do | |
let subSize = size / div | |
let subNum = num + (int64 i) * subSize | |
skynet subNum subSize agent.Post | |
skynet 0L 1000000L (printfn "Value = %d") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment