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