From 2d2bdba4967741d36b4d4febcffcbe369097ea61 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 25 Feb 2024 11:24:51 +0000 Subject: [PATCH] Add a couple of benchmarks for AsOLEPropertiesContainer --- sources/Test/OpenMcdf.Benchmark/Extensions.cs | 41 +++++++++++++++++++ .../OpenMcdf.Benchmark.csproj | 13 +++++- sources/Test/OpenMcdf.Benchmark/Program.cs | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 sources/Test/OpenMcdf.Benchmark/Extensions.cs diff --git a/sources/Test/OpenMcdf.Benchmark/Extensions.cs b/sources/Test/OpenMcdf.Benchmark/Extensions.cs new file mode 100644 index 00000000..1781476f --- /dev/null +++ b/sources/Test/OpenMcdf.Benchmark/Extensions.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using BenchmarkDotNet.Attributes; +using OpenMcdf.Extensions; + +namespace OpenMcdf.Benchmark +{ + // Simple benchmarks for reading OLE Properties with OpenMcdf.Extensions. + [SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.NetCoreApp31)] + [MemoryDiagnoser] + public class ExtensionsRead + { + // Keep the Storage as a member, as we're only testing the OLEProperties bits, not the underlying CompoundFile + private readonly CompoundFile udTestFile; + + // Load the test file on creation + public ExtensionsRead() + { + string testFile = Path.Combine("TestFiles", "winUnicodeDictionary.doc"); + this.udTestFile = new CompoundFile(testFile); + } + + [GlobalCleanup] + public void GlobalCleanup() + { + udTestFile.Close(); + } + + [Benchmark] + public void TestReadSummaryInformation() + { + this.udTestFile.RootStorage.GetStream("\u0005SummaryInformation").AsOLEPropertiesContainer(); + } + + [Benchmark] + public void TestReadDocumentSummaryInformation() + { + this.udTestFile.RootStorage.GetStream("\u0005DocumentSummaryInformation").AsOLEPropertiesContainer(); + } + } +} \ No newline at end of file diff --git a/sources/Test/OpenMcdf.Benchmark/OpenMcdf.Benchmark.csproj b/sources/Test/OpenMcdf.Benchmark/OpenMcdf.Benchmark.csproj index cd12f4e0..f20af7c3 100644 --- a/sources/Test/OpenMcdf.Benchmark/OpenMcdf.Benchmark.csproj +++ b/sources/Test/OpenMcdf.Benchmark/OpenMcdf.Benchmark.csproj @@ -6,11 +6,22 @@ - + + + + + + + + + PreserveNewest + + + diff --git a/sources/Test/OpenMcdf.Benchmark/Program.cs b/sources/Test/OpenMcdf.Benchmark/Program.cs index f441ba1d..a6459efa 100644 --- a/sources/Test/OpenMcdf.Benchmark/Program.cs +++ b/sources/Test/OpenMcdf.Benchmark/Program.cs @@ -6,7 +6,7 @@ internal class Program { private static void Main(string[] args) { - var summary = BenchmarkRunner.Run(); + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); } } } \ No newline at end of file