@@ -6,23 +6,15 @@ open System
66open BenchmarkDotNet.Attributes
77open BenchmarkDotNet.Diagnosers
88open BenchmarkDotNet.Configs
9- open BenchmarkDotNet.Jobs
109open BenchmarkDotNet.Running
1110open BenchmarkDotNet.Validators
1211open BenchmarkDotNet.Exporters
13- open BenchmarkDotNet.Environments
14- open System.Reflection
15- open BenchmarkDotNet.Configs
1612
1713open System.Text .Json
1814open System.Text .Json .Serialization
1915open Newtonsoft.Json
20- open Newtonsoft.Json .Linq
2116
22- type TestRecord =
23- { name: string
24- thing: bool option
25- time: System .DateTimeOffset }
17+ type TestRecord = { name: string ; thing: bool option ; time: DateTimeOffset }
2618
2719type SimpleClass () =
2820 member val Name : string = null with get, set
@@ -94,6 +86,29 @@ type ReflectionComparison() =
9486 for i in 0 .. this.Iterations do
9587 TypeCache.isRecord typeof< TestRecord> |> ignore
9688
89+ type ListDeserialization < 't >( instance : 't ) =
90+ let options = JsonFSharpOptions() .ToJsonSerializerOptions()
91+
92+ [<Params( 10 , 100 ) >]
93+ member val ListLength = 0 with get, set
94+
95+ member val String = " " with get, set
96+
97+ [<GlobalSetup>]
98+ member this.InitList () =
99+ this.String <- System.Text.Json.JsonSerializer.Serialize( Array.replicate this.ListLength instance, options)
100+
101+ [<Benchmark>]
102+ member this.ListCollector () =
103+ System.Text.Json.JsonSerializer.Deserialize< 't list>( this.String, options)
104+
105+ [<Benchmark>]
106+ member this.AsArray () =
107+ System.Text.Json.JsonSerializer.Deserialize< 't array>( this.String, options)
108+ |> List.ofArray
109+
110+ type ListDeserialization () =
111+ inherit ListDeserialization< int>( 42 )
97112
98113let config =
99114 ManualConfig
@@ -106,7 +121,8 @@ let defaultSwitch () =
106121 BenchmarkSwitcher(
107122 [| typeof< Records>
108123 typeof< Classes>
109- typeof< ReflectionComparison> |]
124+ typeof< ReflectionComparison>
125+ typeof< ListDeserialization> |]
110126 )
111127
112128
0 commit comments