public void AsyncFaster()
{
const int ITERATIONS = 100000;
// ReSharper disable once TooWideLocalVariableScope
byte[] compressSync;
#pragma warning disable 219
byte[] decompressSync;
#pragma warning restore 219
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < ITERATIONS; i++)
{
compressSync = GZipCompressor.Instance.Compress(VALUE);
// ReSharper disable once RedundantAssignment
decompressSync = GZipCompressor.Instance.Decompress(compressSync);
}
long sync = sw.ElapsedTicks;
// ReSharper disable once TooWideLocalVariableScope
byte[] compressAsync;
#pragma warning disable 219
byte[] decompressAsync;
#pragma warning restore 219
sw = Stopwatch.StartNew();
for (int i = 0; i < ITERATIONS; i++)
{
Task.Run(async () =>
{
compressAsync = await GZipCompressor.Instance.CompressAsync(VALUE);
decompressAsync = await GZipCompressor.Instance.DecompressAsync(compressAsync);
});
}
long async = sw.ElapsedTicks;
string debugInfo = string.Empty;
debugInfo += "async vs sync: " + (((float)async / sync) * 100) + "%\n";
debugInfo += "\n";
Console.WriteLine(debugInfo);
Assert.True(sync > async);
}
}