Skip to content

Instantly share code, notes, and snippets.

@palladin
Last active September 25, 2021 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palladin/39fc0e10f88c57962ecd54f7602ae835 to your computer and use it in GitHub Desktop.
Save palladin/39fc0e10f88c57962ecd54f7602ae835 to your computer and use it in GitHub Desktop.
Struct Unions Perf
#time
[<Struct>]
type ResultStruct<'T, 'TError> =
| OkS of ok : 'T
| ErrorS of error : 'TError
type ResultClass<'T, 'TError> =
| OkC of ok : 'T
| ErrorC of error : 'TError
let data = [|1..100000000|]
data |> Seq.map(fun x -> OkS x) |> Seq.map id |> Seq.length // Real: 00:00:08.081, CPU: 00:00:08.046, GC gen0: 0, gen1: 0, gen2: 0
data |> Seq.map(fun x -> OkC x) |> Seq.map id |> Seq.length // Real: 00:00:06.668, CPU: 00:00:06.671, GC gen0: 381, gen1: 0, gen2: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment