public static ProfilerResult Profile(IProfilable instance) { var profileResults = new ProfilerResult(instance); // Perform a test run instance.Setup(); instance.Run(); instance.Cleanup(); Stopwatch timer = new Stopwatch(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); for (int i = 0; i < instance.ProfileIterations; i++) { instance.Setup(); timer.Start(); instance.Run(); timer.Stop(); profileResults.Records.Add(timer.Elapsed.TotalMilliseconds); timer.Reset(); } profileResults.ProcessResults(); return(profileResults); }
/// <summary> /// Creates a new ProfilerResult instance with an instance of the class to be profiled. /// </summary> /// <param name="instance">An instance of the class to be profiled.</param> public ProfilerResult(IProfilable instance) { this.ProfiledInstance = instance; this.Records = new List <double>(instance.ProfileIterations); }