-
-
Save hasipon/071d1c92618aea26788b37746a0d21f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace JsonReader | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var data = new List<object>(); | |
const int len = 300000; | |
long sum = 0; | |
var rnd = new System.Random(); | |
for (int i = 0; i < len; ++i) | |
{ | |
var x = rnd.Next(); | |
sum += x; | |
data.Add(new {hoge = x, piyo = "foo"}); | |
} | |
var json = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(data); | |
var sw3 = new System.Diagnostics.Stopwatch(); | |
var sw4 = new System.Diagnostics.Stopwatch(); | |
sw3.Start(); | |
var a = Hurisake.JsonDeserializer.Deserialize(json)!.Value; | |
// https://github.com/neuecc/Utf8Json | |
// var a = Utf8Json.JsonSerializer.Deserialize<dynamic>(json); | |
sw3.Stop(); | |
sw4.Start(); | |
long sum2 = 0; | |
if (a.Count != len) throw new Exception(); | |
for (int i = 0; i < a.Count; ++i) | |
{ | |
sum2 += (int)a[i]["hoge"]; | |
} | |
if (sum != sum2) throw new Exception(); | |
sw4.Stop(); | |
Console.WriteLine(sw3.ElapsedMilliseconds); | |
Console.WriteLine(sw4.ElapsedMilliseconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment