Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #time "on"
- type MyRecType() =
- let list = System.Collections.Generic.List()
- member this.DoWork() =
- let mutable tcs = (System.Runtime.CompilerServices.AsyncTaskMethodBuilder<int>.Create())
- let returnTask = tcs.Task // NB! must access this property first
- let mutable local = 1
- let rec outerLoop() =
- if local < 1000000 then
- innerLoop(1)
- else
- tcs.SetResult(local)
- ()
- and innerLoop(inc:int) =
- if local % 2 = 0 then
- local <- local + inc
- outerLoop()
- else
- list.Add(local) // just fake access to a field to illustrate the pattern
- local <- local + 1
- innerLoop(inc)
- outerLoop()
- returnTask
- let instance = MyRecType()
- instance.DoWork().Result
- > Real: 00:00:00.019, CPU: 00:00:00.031, GC gen0: 0, gen1: 0, gen2: 0
- > val it : int = 1000001
- member this.DoWork2() =
- let mutable tcs = (System.Runtime.CompilerServices.AsyncTaskMethodBuilder<int>.Create())
- let returnTask = tcs.Task // NB! must access this property first
- let mutable local = 1
- let rec loop(isOuter:bool, inc:int) =
- if isOuter then
- if local < 1000000 then
- loop(false,1)
- else
- tcs.SetResult(local)
- ()
- else
- if local % 2 = 0 then
- local <- local + inc
- loop(true,1)
- else
- list.Add(local) // just fake access to a field to illustrate the pattern
- local <- local + 1
- loop(false,1)
- loop(true,1)
- returnTask
- > Real: 00:00:00.004, CPU: 00:00:00.015, GC gen0: 0, gen1: 0, gen2: 0
- > val it : int = 1000001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement