Collecting data about cbor time

This commit is contained in:
2025-06-30 11:45:59 +03:00
parent c14f0498a8
commit af6e7b6547
4 changed files with 17 additions and 7 deletions
+2 -1
View File
@@ -26,7 +26,8 @@ namespace Example.Frontend
if (value)
{
Console.BackgroundColor = ConsoleColor.Green;
}else Console.BackgroundColor = ConsoleColor.Gray;
}
else Console.BackgroundColor = ConsoleColor.Gray;
Console.Write($"{field.Name}");
Console.BackgroundColor = ConsoleColor.Black;
+2 -2
View File
@@ -10,11 +10,11 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;</DefineConstants>
<DefineConstants>TRACE;JUST_LOAD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants></DefineConstants>
<DefineConstants>JUST_LOAD</DefineConstants>
</PropertyGroup>
<ItemGroup>
+6 -3
View File
@@ -45,6 +45,7 @@ class Program
Console.WriteLine(builder.GetModule<IEndPointContext>().HostId);
var context = builder.GetModule<RemoteInstanceRepository>();
#if !JUST_LOAD
var factory =
context.GetSingletonObject<IPrinterFactory>(
builder.GetModule<IEndPointContext>());
@@ -111,11 +112,11 @@ class Program
}
DemoCheck.Dispose = true;
#endif
var loadSingleton = context.GetSingletonObject<ILoadTest>(builder.GetModule<IEndPointContext>());
#if !JUST_LOAD
var cts = new CancellationTokenSource();
var token = cts.Token;
var t = Task.Run(async () => await loadSingleton!.AsyncTest(token));
@@ -124,7 +125,8 @@ class Program
cts.Cancel();
Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}");
DemoCheck.TaskCancelation = true;
#endif
const int iterations = 10000;
var timer = Stopwatch.StartNew();
var x = 0;
@@ -137,6 +139,7 @@ class Program
Console.WriteLine("X is {0}", x);
Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds);
Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms");
Console.WriteLine($"Serialization time: {CborSerializationToolkit.SerializationTime}");
frontendBridge.Disconnect();
+7 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Formats.Cbor;
using System.Linq;
using System.Reflection;
@@ -12,11 +13,16 @@ namespace mROA.Cbor
{
public class CborSerializationToolkit : IContextualSerializationToolKit
{
public static TimeSpan SerializationTime = TimeSpan.Zero;
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
{
var sw = Stopwatch.StartNew();
var writer = new CborWriter();
WriteData(objectToSerialize, writer, context);
return writer.Encode();
var result = writer.Encode();
sw.Stop();
SerializationTime = SerializationTime.Add(sw.Elapsed);
return result;
}
public int Serialize(object objectToSerialize, Span<byte> destination, IEndPointContext context)