about summary refs log tree commit diff
path: root/Utilities/LibMatrix.EventTypes.Benchmark/Program.cs
blob: 512c066cbe69268c6bc06672cf5fb8f0abb1eff5 (plain) (blame)
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
using System.Text.Json;
using ArcaneLibs.Extensions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using LibMatrix.EventTypes;
using LibMatrix.EventTypes.Spec;

BenchmarkRunner.Run<Tests>();

[ShortRunJob]
[MemoryDiagnoser]
public class Tests {
    // public MatrixEventCollection<MatrixEventContent> Members = [
    //     new MatrixEvent<RoomMembershipEventContent>() {
    //         Content = new() {
    //             Membership = "join"
    //         }
    //     }
    // ];

    private static string eventJson = File.ReadAllText("test-event.json");
    private static MatrixEvent<RoomMembershipEventContent> evt2 = JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(eventJson);
    [Benchmark]
    public void Deserialise() {
        JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(eventJson);
    }
    [Benchmark]
    public void Serialise() {
        evt2.ToJson();
    }
    
    [Benchmark]
    public void Modify() {
        evt2.Content.Membership = "meow";
    }
}