public override void Run() { long st = Runtime.NanoTime(); this.crc.Reset(); for (int i = 0; i < trials; i++) { this.crc.Update(bytes, 0, size); } long et = Runtime.NanoTime(); double secsElapsed = (et - st) / 1000000000.0d; results[index] = new TestPureJavaCrc32.PerformanceTest.BenchResult(this.crc.GetValue (), mbProcessed / secsElapsed); }
/// <exception cref="System.Exception"/> private static TestPureJavaCrc32.PerformanceTest.BenchResult DoBench(Type clazz, int numThreads, byte[] bytes, int size) { Thread[] threads = new Thread[numThreads]; TestPureJavaCrc32.PerformanceTest.BenchResult[] results = new TestPureJavaCrc32.PerformanceTest.BenchResult [threads.Length]; { int trials = BytesPerSize / size; double mbProcessed = trials * size / 1024.0 / 1024.0; Constructor <Checksum> ctor = clazz.GetConstructor(); for (int i = 0; i < threads.Length; i++) { int index = i; threads[i] = new _Thread_327(ctor, trials, bytes, size, results, index, mbProcessed ); } } for (int i_1 = 0; i_1 < threads.Length; i_1++) { threads[i_1].Start(); } for (int i_2 = 0; i_2 < threads.Length; i_2++) { threads[i_2].Join(); } long expected = results[0].value; double sum = results[0].mbps; for (int i_3 = 1; i_3 < results.Length; i_3++) { if (results[i_3].value != expected) { throw new Exception(clazz.Name + " results not matched."); } sum += results[i_3].mbps; } return(new TestPureJavaCrc32.PerformanceTest.BenchResult(expected, sum / results. Length)); }
/// <exception cref="System.Exception"/> private static void DoBench(IList <Type> crcs, byte[] bytes, int size, TextWriter @out) { string numBytesStr = " #Bytes "; string numThreadsStr = "#T"; string diffStr = "% diff"; @out.Write('|'); PrintCell(numBytesStr, 0, @out); PrintCell(numThreadsStr, 0, @out); for (int i = 0; i < crcs.Count; i++) { Type c = crcs[i]; @out.Write('|'); PrintCell(c.Name, 8, @out); for (int j = 0; j < i; j++) { PrintCell(diffStr, diffStr.Length, @out); } } @out.Printf("\n"); for (int numThreads = 1; numThreads <= 16; numThreads <<= 1) { @out.Printf("|"); PrintCell(size.ToString(), numBytesStr.Length, @out); PrintCell(numThreads.ToString(), numThreadsStr.Length, @out); TestPureJavaCrc32.PerformanceTest.BenchResult expected = null; IList <TestPureJavaCrc32.PerformanceTest.BenchResult> previous = new AList <TestPureJavaCrc32.PerformanceTest.BenchResult >(); foreach (Type c in crcs) { System.GC.Collect(); TestPureJavaCrc32.PerformanceTest.BenchResult result = DoBench(c, numThreads, bytes , size); PrintCell(string.Format("%9.1f", result.mbps), c.Name.Length + 1, @out); //check result if (c == zip) { expected = result; } else { if (expected == null) { throw new RuntimeException("The first class is " + c.FullName + " but not " + zip .FullName); } else { if (result.value != expected.value) { throw new RuntimeException(c + " has bugs!"); } } } //compare result with previous foreach (TestPureJavaCrc32.PerformanceTest.BenchResult p in previous) { double diff = (result.mbps - p.mbps) / p.mbps * 100; PrintCell(string.Format("%5.1f%%", diff), diffStr.Length, @out); } previous.AddItem(result); } @out.Printf("\n"); } }