pimbrouwers / Jay

An F# JSON parser & serializer
Apache License 2.0
12 stars 2 forks source link

Performance comparison #1

Open brettrowberry opened 4 years ago

brettrowberry commented 4 years ago

How does the performance compare to other JSON serializers available in F#?

pimbrouwers commented 4 years ago

Sounds like a good idea for a PR ;)

Numpsy commented 1 year ago

Not sure how much of a direct comparison this is, but as an example, if I have a benchmark like

        [Benchmark]
        public Jay.Common.Json ParseWithJay()
        {
            return Jay.Json.Json.parse(jsonText);
        }

        [Benchmark]
        public System.Text.Json.JsonDocument ParseWithJsonDocument()
        {
            return System.Text.Json.JsonDocument.Parse(jsonText);
        }

        [Benchmark]
        public Newtonsoft.Json.Linq.JObject ParseWithJObject()
        {
            return Newtonsoft.Json.Linq.JObject.Parse(jsonText);
        }

and I run it with the json file from https://github.com/danipen/TextMateSharp/blob/master/src/TextMateSharp.Grammars/Resources/Grammars/csharp/syntaxes/csharp.tmLanguage.json (~108KB of Json) then I get this:

Job=.NET 7.0  Runtime=.NET 7.0

|                Method |       Mean |    Error |   StdDev |     Gen0 |     Gen1 |    Gen2 |  Allocated |
|---------------------- |-----------:|---------:|---------:|---------:|---------:|--------:|-----------:|
|          ParseWithJay |   501.5 us |  9.75 us |  9.12 us | 101.0742 |  69.8242 |       - |   621.2 KB |
| ParseWithJsonDocument |   377.1 us |  4.46 us |  3.48 us |  83.0078 |  83.0078 | 83.0078 |  256.19 KB |
|      ParseWithJObject | 1,302.7 us | 25.67 us | 46.29 us | 246.0938 | 218.7500 |       - | 1515.61 KB |

I haven't used it for writing Json, so I haven't tested that