private void PerformMeasurements() { // Settings. var iterations = 1000; var warningLimit = 100000; // 0.1s var badLimit = 300000; // 0.3s // Perform conversions. var runtime = StorageAccess.ToRuntime(this.m_Layer); IGenerator compiled = null; try { compiled = StorageAccess.ToCompiled(runtime); } catch (Exception) { // Failed to compile layer. } // First check how long it takes for the runtime layer to do 1000 operations of 8x8x8. var runtimeStart = DateTime.Now; var runtimeComputations = 0; for (var i = 0; i < iterations; i++) { runtime.GenerateData(0, 0, 0, 8, 8, 8, out runtimeComputations); } var runtimeEnd = DateTime.Now; // Now check how long it takes the compiled layer to do 1000 operations of 8x8x8. var compiledStart = DateTime.Now; var compiledComputations = 0; if (compiled != null) { try { for (var i = 0; i < iterations; i++) { compiled.GenerateData(0, 0, 0, 8, 8, 8, out compiledComputations); } } catch { compiled = null; } } var compiledEnd = DateTime.Now; // Determine the per-operation cost. var runtimeCost = runtimeEnd - runtimeStart; var compiledCost = compiledEnd - compiledStart; var runtimeus = Math.Round((runtimeCost.TotalMilliseconds / iterations) * 1000, 0); // Microseconds. var compiledus = Math.Round((compiledCost.TotalMilliseconds / iterations) * 1000, 0); // Define colors and determine values. var okay = new SolidBrush(Color.LightGreen); var warning = new SolidBrush(Color.Orange); var bad = new SolidBrush(Color.IndianRed); var runtimeColor = okay; var compiledColor = okay; if (runtimeus > warningLimit) { runtimeColor = warning; } if (compiledus > warningLimit) { compiledColor = warning; } if (runtimeus > badLimit) { runtimeColor = bad; } if (compiledus > badLimit) { compiledColor = bad; } // Draw performance measurements. Bitmap bitmap; if (runtimeComputations != compiledComputations && compiled != null) { bitmap = new Bitmap(128, 48); } else { bitmap = new Bitmap(128, 32); } var graphics = Graphics.FromImage(bitmap); var font = new Font(SystemFonts.DefaultFont, FontStyle.Bold); graphics.Clear(Color.Black); if (runtimeComputations != compiledComputations && compiled != null) { graphics.DrawString("Computation mismatch!", font, bad, new PointF(0, 0)); graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 16)); graphics.DrawString(runtimeComputations + "c", font, runtimeColor, new PointF(70, 16)); if (compiled != null) { graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 32)); graphics.DrawString(compiledComputations + "c", font, compiledColor, new PointF(70, 32)); } else { graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 32)); } } else { graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 0)); graphics.DrawString(runtimeus + "\xB5s", font, runtimeColor, new PointF(70, 0)); if (compiled != null) { graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 16)); graphics.DrawString(compiledus + "\xB5s", font, compiledColor, new PointF(70, 16)); } else { graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 16)); } } if (this.m_AdditionalInformation != null) { this.m_AdditionalInformation.Dispose(); } this.m_AdditionalInformation = bitmap; // TEMPORARY: Use the compiled layer to re-render the output. if (compiled != null) { this.m_CompiledBitmap = AlgorithmFlowImageGeneration.RegenerateImageForLayer(this.m_Layer, TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.X, TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Y, TemporaryCrapBecauseIDidNotReallyDesignThingsVeryWell.Z, 64, 64, 64, true); } }