Last active
September 25, 2021 17:52
-
-
Save palladin/39fc0e10f88c57962ecd54f7602ae835 to your computer and use it in GitHub Desktop.
Struct Unions Perf
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 | |
[<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