private TimeSpan DoTimingRun(Crc32ModeS calculator, bool useFastMethod, bool useLongMessage, int count) { var message = new byte[useLongMessage ? 11 : 4]; var random = new Random(); DateTime start, finish; if(useFastMethod) { start = DateTime.UtcNow; for(var i = 0;i < count;++i) { random.NextBytes(message); calculator.ComputeChecksumBytes(message, 0, message.Length); } finish = DateTime.UtcNow; } else if(useLongMessage) { start = DateTime.UtcNow; for(var i = 0;i < count;++i) { random.NextBytes(message); calculator.ComputeChecksumBytesTraditional88(message); } finish = DateTime.UtcNow; } else { start = DateTime.UtcNow; for(var i = 0;i < count;++i) { random.NextBytes(message); calculator.ComputeChecksumBytesTraditional32(message); } finish = DateTime.UtcNow; } return finish - start; }
public void Crc32ModeS_Timing_Test() { var crcCalculator = new Crc32ModeS(); var count = 1000000; var fastShortTiming = DoTimingRun(crcCalculator, true, false, count); var fastLongTiming = DoTimingRun(crcCalculator, true, true, count); var slowShortTiming = DoTimingRun(crcCalculator, false, false, count); var slowLongTiming = DoTimingRun(crcCalculator, false, true, count); Assert.Inconclusive("Timings on {0:N0} messages: 'Fast' and short: {1}, 'Fast' and long: {2}, 'Slow' and short: {3}, 'Slow' and long: {4}", count, fastShortTiming, fastLongTiming, slowShortTiming, slowLongTiming); }