Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ paket-files/
**/[Oo]bj/
**/[Bb]in/
.vs/
**/BenchmarkDotNet.Artifacts
17 changes: 17 additions & 0 deletions FSharp.SystemTextJson.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CC287195
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.SystemTextJson.Tests", "tests\FSharp.SystemTextJson.Tests\FSharp.SystemTextJson.Tests.fsproj", "{FD908F6A-5B23-4FAA-B52B-65379E6D5539}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{E7CE56A4-261F-495E-B1AE-F0333FF932CA}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.SystemTextJson.Benchmarks", "benchmarks\FSharp.SystemTextJson.Benchmarks\FSharp.SystemTextJson.Benchmarks.fsproj", "{507E640D-9E7B-4386-994B-913E4CDD64D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,13 +61,26 @@ Global
{FD908F6A-5B23-4FAA-B52B-65379E6D5539}.Release|x64.Build.0 = Release|Any CPU
{FD908F6A-5B23-4FAA-B52B-65379E6D5539}.Release|x86.ActiveCfg = Release|Any CPU
{FD908F6A-5B23-4FAA-B52B-65379E6D5539}.Release|x86.Build.0 = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|x64.ActiveCfg = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|x64.Build.0 = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|x86.ActiveCfg = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Debug|x86.Build.0 = Debug|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|Any CPU.Build.0 = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|x64.ActiveCfg = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|x64.Build.0 = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|x86.ActiveCfg = Release|Any CPU
{507E640D-9E7B-4386-994B-913E4CDD64D0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5DD5F99C-D4B4-4DF6-A638-EEE6B0CCCAFB} = {79B2E5F7-01BA-459B-9269-71D41C73D228}
{FD908F6A-5B23-4FAA-B52B-65379E6D5539} = {CC287195-657A-4E49-A957-4D4B5919ACFB}
{507E640D-9E7B-4386-994B-913E4CDD64D0} = {E7CE56A4-261F-495E-B1AE-F0333FF932CA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78789C56-BAE0-436E-BDDF-789B98CEC9A5}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.SystemTextJson\FSharp.SystemTextJson.fsproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
66 changes: 66 additions & 0 deletions benchmarks/FSharp.SystemTextJson.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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 Serialization () =

let instance =
{ name = "sample"
thing = Some true
time = System.DateTimeOffset.UnixEpoch.AddDays(200.) }

let systemTextOptions =
let options = JsonSerializerOptions()
options.Converters.Add(JsonFSharpConverter())
options


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

member val InstanceArray = [||] with get, set

[<GlobalSetup>]
member this.InitArray () =
this.InstanceArray <- Array.replicate this.ArrayLength instance

[<Benchmark>]
member this.Newtonsoft () = JsonConvert.SerializeObject this.InstanceArray |> ignore

[<Benchmark>]
member this.SystemTextJson () = System.Text.Json.JsonSerializer.Serialize(this.InstanceArray, systemTextOptions) |> ignore

let config =
ManualConfig
.Create(DefaultConfig.Instance)
.With(Job.ShortRun.With(Runtime.Core))
.With(MemoryDiagnoser.Default)
.With(MarkdownExporter.GitHub)
.With(ExecutionValidator.FailOnError)

let defaultSwitch () =
BenchmarkSwitcher([| typeof<Serialization> |])


[<EntryPoint>]
let main _ =
let _summary = BenchmarkRunner.Run<Serialization>(config)
0
3 changes: 3 additions & 0 deletions benchmarks/FSharp.SystemTextJson.Benchmarks/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FSharp.Core
BenchmarkDotNet
Newtonsoft.Json
11 changes: 11 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Paths =
let root = __SOURCE_DIRECTORY__
let sln = root </> "FSharp.SystemTextJson.sln"
let out = root </> "bin"
let benchmarks = root </> "benchmarks" </> "FSharp.SystemTextJson.Benchmarks"

Target.create "Clean" (fun _ ->
!! "**/bin"
Expand Down Expand Up @@ -69,10 +70,20 @@ Target.create "Test" (fun _ ->
Option.iter uploadTests Cli.pushTestsUrl
)

Target.create "Benchmark" (fun _ ->
DotNet.exec (fun o -> { o with
WorkingDirectory = Paths.benchmarks } ) "run" "-c release"
|> fun r ->
if r.OK
then ()
else failwithf "Benchmarks failed with code %d:\n%A" r.ExitCode r.Errors
)

Target.create "All" ignore

"Build"
==> "Test"
==> "Benchmark"
==> "Pack"
==> "All"

Expand Down
Empty file modified build.sh
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ nuget Microsoft.NET.Test.Sdk ~> 16.0.1
nuget System.Text.Json ~> 4.6.0 preview7
nuget xunit ~> 2.4.0
nuget xunit.runner.visualstudio ~> 2.4.0
nuget BenchmarkDotNet
nuget Newtonsoft.Json
63 changes: 63 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@ STORAGE: NONE
RESTRICTION: == netcoreapp3.0
NUGET
remote: https://api.nuget.org/v3/index.json
BenchmarkDotNet (0.11.5)
BenchmarkDotNet.Annotations (>= 0.11.5)
CommandLineParser (>= 2.4.3)
Microsoft.CodeAnalysis.CSharp (>= 2.10)
Microsoft.DotNet.PlatformAbstractions (>= 2.1)
Microsoft.Win32.Registry (>= 4.5)
System.Collections.Immutable (>= 1.5)
System.Diagnostics.FileVersionInfo (>= 4.3)
System.Management (>= 4.5)
System.Reflection.Emit (>= 4.3)
System.Reflection.Emit.Lightweight (>= 4.3)
System.Reflection.Metadata (>= 1.6)
System.Runtime.InteropServices.RuntimeInformation (>= 4.3)
System.Threading.Tasks.Extensions (>= 4.5.2)
System.ValueTuple (>= 4.5)
System.Xml.XmlSerializer (>= 4.3)
System.Xml.XPath.XmlDocument (>= 4.3)
BenchmarkDotNet.Annotations (0.11.5)
CommandLineParser (2.6)
FSharp.Core (4.6.2)
Microsoft.CodeAnalysis.Analyzers (2.9.4)
Microsoft.CodeAnalysis.Common (3.2)
Microsoft.CodeAnalysis.Analyzers (>= 2.9.3)
System.Collections.Immutable (>= 1.5)
System.Memory (>= 4.5.2)
System.Reflection.Metadata (>= 1.6)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)
System.Text.Encoding.CodePages (>= 4.5.1)
System.Threading.Tasks.Extensions (>= 4.5.2)
Microsoft.CodeAnalysis.CSharp (3.2)
Microsoft.CodeAnalysis.Common (3.2)
Microsoft.CodeCoverage (16.2)
Microsoft.DotNet.PlatformAbstractions (2.1)
System.AppContext (>= 4.1)
System.Collections (>= 4.0.11)
System.IO (>= 4.1)
System.IO.FileSystem (>= 4.0.1)
System.Reflection.TypeExtensions (>= 4.1)
System.Runtime.Extensions (>= 4.1)
System.Runtime.InteropServices (>= 4.1)
System.Runtime.InteropServices.RuntimeInformation (>= 4.0)
Microsoft.NET.Test.Sdk (16.0.1)
Microsoft.CodeCoverage (>= 16.0.1)
Microsoft.TestPlatform.TestHost (>= 16.0.1)
Expand Down Expand Up @@ -40,6 +79,9 @@ NUGET
runtime.native.System (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
System.AppContext (4.3)
System.Runtime (>= 4.3)
System.CodeDom (4.5)
System.Collections (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand All @@ -55,6 +97,7 @@ NUGET
System.Runtime.Extensions (>= 4.3)
System.Threading (>= 4.3)
System.Threading.Tasks (>= 4.3)
System.Collections.Immutable (1.5)
System.Collections.NonGeneric (4.3)
System.Diagnostics.Debug (>= 4.3)
System.Globalization (>= 4.3)
Expand Down Expand Up @@ -101,6 +144,16 @@ NUGET
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
System.Runtime (>= 4.3)
System.Diagnostics.FileVersionInfo (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
System.Globalization (>= 4.3)
System.IO (>= 4.3)
System.IO.FileSystem (>= 4.3)
System.IO.FileSystem.Primitives (>= 4.3)
System.Reflection.Metadata (>= 1.4.1)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Runtime.InteropServices (>= 4.3)
System.Diagnostics.Process (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.Win32.Primitives (>= 4.3)
Expand Down Expand Up @@ -182,6 +235,11 @@ NUGET
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Management (4.5)
Microsoft.NETCore.Platforms (>= 2.0)
Microsoft.Win32.Registry (>= 4.5)
System.CodeDom (>= 4.5)
System.Memory (4.5.3)
System.Private.DataContractSerialization (4.3)
System.Collections (>= 4.3)
System.Collections.Concurrent (>= 4.3)
Expand Down Expand Up @@ -249,6 +307,7 @@ NUGET
System.Runtime (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
System.Runtime.CompilerServices.Unsafe (4.5.2)
System.Runtime.Extensions (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
Expand Down Expand Up @@ -292,6 +351,9 @@ NUGET
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
System.Runtime (>= 4.3)
System.Text.Encoding.CodePages (4.5.1)
Microsoft.NETCore.Platforms (>= 2.1.2)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)
System.Text.Encoding.Extensions (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand All @@ -313,6 +375,7 @@ NUGET
System.Threading.ThreadPool (4.3)
System.Runtime (>= 4.3)
System.Runtime.Handles (>= 4.3)
System.ValueTuple (4.5)
System.Xml.ReaderWriter (4.3.1)
System.Collections (>= 4.3)
System.Diagnostics.Debug (>= 4.3)
Expand Down