Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add large write perf methods #222

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion OpenMcdf.Perf/OpenMcdf.Perf.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net4.8;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OpenMcdf\OpenMcdf.csproj" />
<ProjectReference Include="..\StructuredStorage\StructuredStorage.csproj" />
</ItemGroup>

</Project>
72 changes: 60 additions & 12 deletions OpenMcdf.Perf/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,79 @@ internal sealed class Program
static void Main(string[] args)
{
var stopwatch = Stopwatch.StartNew();
Write(Version.V3, StorageModeFlags.Transacted, 1024 * 1024, 1024 * 1024, 100);
int bufferLength = 1024 * 1024;
int streamLength = 8 * 1024 * 1024;
Write(Version.V3, StorageModeFlags.None, bufferLength, streamLength, 100);
Console.WriteLine($"Elapsed: {stopwatch.Elapsed}");
}

static void Write(Version version, StorageModeFlags storageModeFlags, int bufferLength, int streamLength, int iterations)
public static void Write(Version version, StorageModeFlags storageModeFlags, int bufferLength, int streamLength, int iterations)
{
// Fill with bytes equal to their position modulo 256
byte[] expectedBuffer = new byte[bufferLength];
for (int i = 0; i < bufferLength; i++)
expectedBuffer[i] = (byte)i;
byte[] buffer = new byte[bufferLength];

//byte[] actualBuffer = new byte[length];

//using MemoryStream memoryStream = new(2 * length * iterations);
using FileStream baseStream = File.Create(Path.GetTempFileName());
//using FileStream baseStream = File.Create(Path.GetTempFileName());
using MemoryStream baseStream = new(streamLength * iterations * 2);
for (int i = 0; i < iterations; i++)
{
using var rootStorage = RootStorage.Create(baseStream, version, storageModeFlags);
using var rootStorage = RootStorage.Create(baseStream, version, storageModeFlags | StorageModeFlags.LeaveOpen);
using Stream stream = rootStorage.CreateStream("TestStream");

for (int j = 0; j < streamLength / bufferLength; j++)
stream.Write(expectedBuffer, 0, expectedBuffer.Length);
stream.Write(buffer, 0, buffer.Length);

if (storageModeFlags.HasFlag(StorageModeFlags.Transacted))
rootStorage.Commit();
}
}

public static void MultiStorageAndStreamWrite()
{
int storageCount = 8;
int streamCount = 8;
int writeCount = 1024;
byte[] buffer = new byte[32 * 512];

Microsoft.IO.RecyclableMemoryStreamManager manager = new ();
Microsoft.IO.RecyclableMemoryStream baseStream = new(manager);
baseStream.Capacity = 2 * (storageCount * buffer.Length * writeCount + storageCount * (streamCount - 1) * buffer.Length);

using var rootStorage = RootStorage.Create(baseStream, Version.V4);
for (int k = 0; k < storageCount; k++)
{
Console.WriteLine($"Creating Storage {k}");
Storage storage = rootStorage.CreateStorage($"TestStorage{k}");
for (int i = 0; i < streamCount; i++)
{
using CfbStream stream = storage.CreateStream($"TestStream{i}");

int to = i == 0 ? writeCount : 1;
for (int j = 0; j < to; j++)
stream.Write(buffer, 0, buffer.Length);
}
}
}

public static void MultiStorageAndStreamWriteBaseline()
{
int storageCount = 8;
int streamCount = 8;
int writeCount = 1024;
byte[] buffer = new byte[32 * 512];
int capacity = 2 * (storageCount * buffer.Length * writeCount + storageCount * (streamCount - 1) * buffer.Length);

using var rootStorage = StructuredStorage.Storage.CreateInMemory(capacity);
for (int k = 0; k < storageCount; k++)
{
Console.WriteLine($"Creating Storage {k}");
var storage = rootStorage.CreateStorage($"TestStorage{k}");
for (int i = 0; i < streamCount; i++)
{
using var stream = storage.CreateStream($"TestStream{i}");

int to = i == 0 ? writeCount : 1;
for (int j = 0; j < to; j++)
stream.Write(buffer, 0, buffer.Length);
}
}
}
}