Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions benchmarks/FSharp.SystemTextJson.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Diagnosers
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Jobs
open BenchmarkDotNet.Running
open BenchmarkDotNet.Validators
open BenchmarkDotNet.Exporters
open BenchmarkDotNet.Environments
open System.Reflection
open BenchmarkDotNet.Configs

open System.Text.Json
open System.Text.Json.Serialization
open Newtonsoft.Json
open Newtonsoft.Json.Linq

type TestRecord =
{ name: string
thing: bool option
time: System.DateTimeOffset }
type TestRecord = { name: string; thing: bool option; time: DateTimeOffset }

type SimpleClass() =
member val Name: string = null with get, set
Expand Down Expand Up @@ -119,6 +111,30 @@ type TupleComparison() =
member this.RefSpecialized() =
System.Text.Json.JsonSerializer.Deserialize<int * bool>("[1,true]", specializedOptions)

type ListDeserialization<'t>(instance: 't) =
let options = JsonFSharpOptions().ToJsonSerializerOptions()

[<Params(10, 100)>]
member val ListLength = 0 with get, set

member val String = "" with get, set

[<GlobalSetup>]
member this.InitList() =
this.String <- System.Text.Json.JsonSerializer.Serialize(Array.replicate this.ListLength instance, options)

[<Benchmark>]
member this.ListCollector() =
System.Text.Json.JsonSerializer.Deserialize<'t list>(this.String, options)

[<Benchmark>]
member this.AsArray() =
System.Text.Json.JsonSerializer.Deserialize<'t array>(this.String, options)
|> List.ofArray

type ListDeserialization() =
inherit ListDeserialization<int>(42)

let config =
ManualConfig
.Create(DefaultConfig.Instance)
Expand All @@ -131,7 +147,8 @@ let defaultSwitch () =
[| typeof<Records>
typeof<Classes>
typeof<ReflectionComparison>
typeof<TupleComparison> |]
typeof<TupleComparison>
typeof<ListDeserialization> |]
)


Expand Down
8 changes: 4 additions & 4 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ frameworks netstandard2.0
storage none
source https://api.nuget.org/v3/index.json

nuget FSharp.Core >= 4.7.0 lowest_matching:true
nuget FSharp.Core >= 6.0 lowest_matching:true
nuget Microsoft.SourceLink.GitHub prerelease copy_local:true
nuget Nerdbank.GitVersioning copy_local:true
nuget System.Text.Json >= 6.0.10 lowest_matching: true
nuget System.Text.Json >= 8.0.5 lowest_matching: true

group test
framework net9.0
storage none
source https://api.nuget.org/v3/index.json

nuget FSharp.Core >= 5.0
nuget FSharp.Core >= 6.0
nuget FsCheck.XUnit
nuget Microsoft.NET.Test.Sdk
nuget System.Text.Json >= 8.0.5 prerelease
nuget System.Text.Json >= 8.0.5
nuget xunit
nuget xunit.runner.visualstudio
nuget BenchmarkDotNet
Expand Down
Loading