public PerformanceTestResult Execute() { var testResult = new PerformanceTestResult(); var stopwatch = new Stopwatch(); stopwatch.Start(); var testData = dataProvider.GetData(); stopwatch.Stop(); testResult.InitializationTime = stopwatch.Elapsed; var participantsTestResults = new List <ParticipantTestResult>(); foreach (var participant in participants) { var participantTestResult = new ParticipantTestResult { ParticipantName = participant.Name, NumberOfExecutions = testData.Length }; stopwatch.Reset(); stopwatch.Start(); participant.Initialize(); stopwatch.Stop(); participantTestResult.InitializationTime = stopwatch.Elapsed; stopwatch.Reset(); stopwatch.Start(); foreach (var model in testData) { participant.Convert(model); } stopwatch.Stop(); participantTestResult.TotalConvertionTime = stopwatch.Elapsed; stopwatch.Reset(); stopwatch.Start(); foreach (var model in testData) { participant.MapData(model); } stopwatch.Stop(); participantTestResult.TotalMapTime = stopwatch.Elapsed; participantsTestResults.Add(participantTestResult); } testResult.ParticipantsResults = participantsTestResults.ToArray(); return(testResult); }
private void FlashMapperInternal_Click(object sender, RoutedEventArgs e) { var stopwatch = new Stopwatch(); var mappingConfiguration = new MappingConfiguration(); mappingConfiguration.CreateMapping <IdenticalTestSource, Destination>(); var storage = (IMappingsStorage)typeof(MappingConfiguration) .GetField("mappingsStorage", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(mappingConfiguration); stopwatch.Start(); var testData = identicalModelsDataProvider.GetData(); stopwatch.Stop(); TestName.Content = "InternalTest results"; TestInfo.Content = $"Initialilzation time {stopwatch.Elapsed:c}"; stopwatch.Reset(); var numberOfExecutions = configuration.NumberOfExecutions; var testResults = new List <Tuple <string, TimeSpan> >(); stopwatch.Start(); for (int i = 0; i < numberOfExecutions; i++) { storage.GetMapping <IdenticalTestSource, Destination>(); } stopwatch.Stop(); testResults.Add(new Tuple <string, TimeSpan>("GetMapping", stopwatch.Elapsed)); stopwatch.Reset(); var convertMethod = storage.GetMapping <IdenticalTestSource, Destination>().BuildFunction; stopwatch.Start(); for (int i = 0; i < numberOfExecutions; i++) { convertMethod(testData[i]); } stopwatch.Stop(); testResults.Add(new Tuple <string, TimeSpan>("Execute", stopwatch.Elapsed)); stopwatch.Reset(); var manualBuilder = new ManualIdenticalBuilder(); stopwatch.Start(); for (int i = 0; i < numberOfExecutions; i++) { manualBuilder.Build(testData[i]); } stopwatch.Stop(); testResults.Add(new Tuple <string, TimeSpan>("ManualExecute", stopwatch.Elapsed)); Expression <Func <IdenticalTestSource, Destination> > manualMethodCall = i => manualBuilder.Build(i); var manualMethodCallCompiled = manualMethodCall.Compile(); stopwatch.Reset(); stopwatch.Start(); for (int i = 0; i < numberOfExecutions; i++) { manualMethodCallCompiled(testData[i]); } stopwatch.Stop(); testResults.Add(new Tuple <string, TimeSpan>("ManualRecompiled", stopwatch.Elapsed)); ResultsGrid.ItemsSource = testResults.Select(r => new { Name = r.Item1, ExecutionTime = r.Item2 }); }