Skip to content

Commit c09a028

Browse files
committed
benchmark: test tuple serialized vs generic
1 parent e2b910a commit c09a028

File tree

1 file changed

+26
-1
lines changed
  • benchmarks/FSharp.SystemTextJson.Benchmarks

1 file changed

+26
-1
lines changed

benchmarks/FSharp.SystemTextJson.Benchmarks/Program.fs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ type ReflectionComparison() =
9494
for i in 0 .. this.Iterations do
9595
TypeCache.isRecord typeof<TestRecord> |> ignore
9696

97+
type TupleComparison() =
98+
99+
let fsharpOptions = JsonFSharpOptions.Default()
100+
let specializedOptions = fsharpOptions.ToJsonSerializerOptions()
101+
let genericOptions =
102+
let o = JsonSerializerOptions()
103+
o.Converters.Add(JsonTupleConverter(fsharpOptions, true))
104+
o
105+
106+
[<Benchmark>]
107+
member this.StructGeneric() =
108+
System.Text.Json.JsonSerializer.Deserialize<struct (int * bool)>("[1,true]", genericOptions)
109+
110+
[<Benchmark>]
111+
member this.StructSpecialized() =
112+
System.Text.Json.JsonSerializer.Deserialize<struct (int * bool)>("[1,true]", specializedOptions)
113+
114+
[<Benchmark>]
115+
member this.RefGeneric() =
116+
System.Text.Json.JsonSerializer.Deserialize<int * bool>("[1,true]", genericOptions)
117+
118+
[<Benchmark>]
119+
member this.RefSpecialized() =
120+
System.Text.Json.JsonSerializer.Deserialize<int * bool>("[1,true]", specializedOptions)
97121

98122
let config =
99123
ManualConfig
@@ -106,7 +130,8 @@ let defaultSwitch () =
106130
BenchmarkSwitcher(
107131
[| typeof<Records>
108132
typeof<Classes>
109-
typeof<ReflectionComparison> |]
133+
typeof<ReflectionComparison>
134+
typeof<TupleComparison> |]
110135
)
111136

112137

0 commit comments

Comments
 (0)