diff --git a/Example.Frontend/DemoCheck.cs b/Example.Frontend/DemoCheck.cs
index efc95aa..1c8930e 100644
--- a/Example.Frontend/DemoCheck.cs
+++ b/Example.Frontend/DemoCheck.cs
@@ -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;
diff --git a/Example.Frontend/Example.Frontend.csproj b/Example.Frontend/Example.Frontend.csproj
index fdac1b1..42db3a4 100644
--- a/Example.Frontend/Example.Frontend.csproj
+++ b/Example.Frontend/Example.Frontend.csproj
@@ -10,11 +10,11 @@
- TRACE;
+ TRACE;JUST_LOAD
-
+ JUST_LOAD
diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs
index e9cd6fc..14843bd 100644
--- a/Example.Frontend/Program.cs
+++ b/Example.Frontend/Program.cs
@@ -45,6 +45,7 @@ class Program
Console.WriteLine(builder.GetModule().HostId);
var context = builder.GetModule();
+ #if !JUST_LOAD
var factory =
context.GetSingletonObject(
builder.GetModule());
@@ -111,11 +112,11 @@ class Program
}
DemoCheck.Dispose = true;
-
+#endif
var loadSingleton = context.GetSingletonObject(builder.GetModule());
-
+#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();
diff --git a/mROA.Cbor/CborSerializationToolkit.cs b/mROA.Cbor/CborSerializationToolkit.cs
index a638eb8..facd5c9 100644
--- a/mROA.Cbor/CborSerializationToolkit.cs
+++ b/mROA.Cbor/CborSerializationToolkit.cs
@@ -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 destination, IEndPointContext context)