Skip to content

Instantly share code, notes, and snippets.

@hasipon
Created December 3, 2021 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasipon/071d1c92618aea26788b37746a0d21f8 to your computer and use it in GitHub Desktop.
Save hasipon/071d1c92618aea26788b37746a0d21f8 to your computer and use it in GitHub Desktop.
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