Skip to content

Commit e2916e3

Browse files
committed
Updating performance test results.
1 parent 78e4262 commit e2916e3

8 files changed

+29
-9
lines changed

About/Data processing time.png

1.35 KB
Loading

About/Memory in use.png

3.79 KB
Loading

About/Total memory allocations.png

5.01 KB
Loading

StackOnlyJsonParser.PerformanceTests/DataGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public byte[] Generate(int elements)
2323
Name = NextName(),
2424
BoxSize = new
2525
{
26-
Width = _random.NextDouble() * 100,
27-
Height = _random.NextDouble() * 100,
28-
Depth = _random.NextDouble() * 100,
26+
Width = _random.Next(10000) * 0.01,
27+
Height = _random.Next(10000) * 0.01,
28+
Depth = _random.Next(10000) * 0.01,
2929
},
3030
AvailableItems = _random.Next(0, 10),
3131
Colors = Colors.Where(_ => _random.Next(2) > 0),

StackOnlyJsonParser.PerformanceTests/Model/HeapProduct.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace StackOnlyJsonParser.PerformanceTests.Model
55
{
6-
internal class HeapProduct
6+
public class HeapProduct
77
{
88
public string Name { get; set; }
99
public DateTime ProductionDate { get; set; }
@@ -13,14 +13,14 @@ internal class HeapProduct
1313
public Dictionary<string, HeapPrice> Regions { get; set; }
1414
}
1515

16-
internal class HeapSize
16+
public class HeapSize
1717
{
1818
public double Width { get; set; }
1919
public double Height { get; set; }
2020
public double Depth { get; set; }
2121
}
2222

23-
internal class HeapPrice
23+
public class HeapPrice
2424
{
2525
public string Currency { get; set; }
2626
public decimal Value { get; set; }

StackOnlyJsonParser.PerformanceTests/Program.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void Main(string[] args)
1919
var data = dataGenerator.Generate(int.Parse(args[1]));
2020
var stringData = Encoding.UTF8.GetString(data);
2121

22-
for (int i = 0; i < 5; i++)
22+
for (int i = 0; i < 21; i++)
2323
{
2424
GC.Collect();
2525
var allocatedBytes = GC.GetAllocatedBytesForCurrentThread();
@@ -35,6 +35,9 @@ static void Main(string[] args)
3535
case "System.Text.Json":
3636
TestHeap2(data);
3737
break;
38+
case "Utf8Json":
39+
TestHeap3(data);
40+
break;
3841
case "Stack":
3942
TestStack(data);
4043
break;
@@ -46,7 +49,8 @@ static void Main(string[] args)
4649
allocatedBytes = GC.GetAllocatedBytesForCurrentThread() - allocatedBytes;
4750
usedBytes = GC.GetTotalMemory(false) - usedBytes;
4851

49-
Console.WriteLine($"{price}\t{args[0]}\t{args[1]}\t{stopwatch.ElapsedMilliseconds}\t{allocatedBytes}\t{usedBytes}");
52+
if (i > 0)
53+
Console.WriteLine($"{price}\t{args[0]}\t{args[1]}\t{stopwatch.ElapsedMilliseconds}\t{allocatedBytes}\t{usedBytes}");
5054
}
5155
}
5256

@@ -80,6 +84,21 @@ static void TestHeap2(ReadOnlySpan<byte> data)
8084
stopwatch.Stop();
8185
}
8286

87+
static void TestHeap3(byte[] data)
88+
{
89+
stopwatch.Restart();
90+
var products = Utf8Json.JsonSerializer.Deserialize<List<HeapProduct>>(data);
91+
92+
foreach (var product in products)
93+
foreach (var color in product.Colors)
94+
if (color == "red")
95+
foreach (var region in product.Regions)
96+
if (region.Key == "PL")
97+
price += product.AvailableItems * region.Value.Value;
98+
99+
stopwatch.Stop();
100+
}
101+
83102
static void TestStack(ReadOnlySpan<byte> data)
84103
{
85104
stopwatch.Restart();

StackOnlyJsonParser.PerformanceTests/StackOnlyJsonParser.PerformanceTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
11+
<PackageReference Include="Utf8Json" Version="1.3.7" />
1112
</ItemGroup>
1213

1314
<ItemGroup>

StackOnlyJsonParser.PerformanceTests/run.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foreach($algorithm in 'Newtonsoft', 'System.Text.Json', 'Stack', 'StackOnly')
1+
foreach($algorithm in 'Newtonsoft', 'System.Text.Json', 'Utf8Json', 'Stack', 'StackOnly')
22
{
33
foreach($elements in 1, 100, 1000, 10000, 100000, 200000, 500000, 1000000, 1500000, 2500000)
44
{

0 commit comments

Comments
 (0)