@@ -6,23 +6,18 @@ 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
2217type TestRecord =
2318 { name: string
2419 thing: bool option
25- time: System . DateTimeOffset }
20+ time: DateTimeOffset }
2621
2722type SimpleClass () =
2823 member val Name : string = null with get, set
@@ -94,6 +89,28 @@ type ReflectionComparison() =
9489 for i in 0 .. this.Iterations do
9590 TypeCache.isRecord typeof< TestRecord> |> ignore
9691
92+ type ListDeserialization < 't >( instance : 't ) =
93+ let options = JsonFSharpOptions() .ToJsonSerializerOptions()
94+
95+ [<Params( 10 , 100 ) >]
96+ member val ListLength = 0 with get, set
97+
98+ member val String = " " with get, set
99+
100+ [<GlobalSetup>]
101+ member this.InitList () =
102+ this.String <- System.Text.Json.JsonSerializer.Serialize( Array.replicate this.ListLength instance, options)
103+
104+ [<Benchmark>]
105+ member this.ListCollector () =
106+ System.Text.Json.JsonSerializer.Deserialize< 't list>( this.String, options)
107+
108+ [<Benchmark>]
109+ member this.AsArray () =
110+ System.Text.Json.JsonSerializer.Deserialize< 't array>( this.String, options)
111+ |> List.ofArray
112+
113+ type ListDeserialization () = inherit ListDeserialization< int>( 42 )
97114
98115let config =
99116 ManualConfig
@@ -106,7 +123,8 @@ let defaultSwitch () =
106123 BenchmarkSwitcher(
107124 [| typeof< Records>
108125 typeof< Classes>
109- typeof< ReflectionComparison> |]
126+ typeof< ReflectionComparison>
127+ typeof< ListDeserialization> |]
110128 )
111129
112130
0 commit comments