-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
41 lines (35 loc) · 1.21 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Text.Json;
namespace dotnet.jsonserializeroptionsperformance
{
class Program
{
class MessageItem
{
public string Message { get; set; }
public string Message2 { get; set; }
public string Message3 { get; set; }
public string Message4 { get; set; }
public string Message5 { get; set; }
}
static void Main(string[] args)
{
var start = DateTime.Now;
var data = new MessageItem { Message = "simple message" };
for (var i = 0; i < 100000; i++)
{
var dataStr = JsonSerializer.Serialize(data, new JsonSerializerOptions { IgnoreNullValues = true });
}
Console.WriteLine($"Slow Looup took: {DateTime.Now - start}");
start = DateTime.Now;
var options = new JsonSerializerOptions { IgnoreNullValues = true };
for (var i = 0; i < 100000; i++)
{
var dataStr = JsonSerializer.Serialize(data, options);
}
Console.WriteLine($"Fast Loop Took: {DateTime.Now - start}");
Console.ReadLine();
return;
}
}
}