Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DryIoc and formatted result output in test bench for readability #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added DryIoc container; formatted results
  • Loading branch information
richardhauer committed Aug 18, 2015
commit 7247134b44384cb457d41b71950d8b5abd2ce830
26 changes: 19 additions & 7 deletions IocBattle.Benchmark/BenchEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Linq;
using System.Diagnostics;
using System.Threading;
using IocBattle.Benchmark.Models;
using System.Collections.Generic;

namespace IocBattle.Benchmark
{
Expand All @@ -14,24 +16,29 @@ public BenchEngine(IContainer container)
_container = container;
}

public void Start()
public List<Result> Start()
{
List<Result> results = new List<Result>();

Result ret = null;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
// Thread.Sleep(1000);

RunBenchmark(_container.SetupForSingletonTest, "Singleton");
ret = RunBenchmark( _container.SetupForSingletonTest, "Singleton" );

GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
results.Add( ret );
// Thread.Sleep(1000);

RunBenchmark(_container.SetupForTransientTest, "Transient");
ret = RunBenchmark(_container.SetupForTransientTest, "Transient");
results.Add( ret );

Console.WriteLine("");
return results;
}

private void RunBenchmark(Action setupAction, string mode)
private Result RunBenchmark(Action setupAction, string mode)
{
var regTimer = new Stopwatch();
var resolveTimer = new Stopwatch();
Expand All @@ -49,8 +56,13 @@ private void RunBenchmark(Action setupAction, string mode)

resolveTimer.Stop();

Console.WriteLine("{0}: - {1} - Registartion time: \t{2}ms", _container.Name, mode, regTimer.Elapsed.TotalMilliseconds);
Console.WriteLine("{0}: - {1} - Component resolve time: \t{2}ms", _container.Name, mode, resolveTimer.Elapsed.TotalMilliseconds);
return new Result
{
Name = _container.Name,
Mode = mode,
RegisterTime = regTimer.Elapsed.TotalMilliseconds,
ResolveTime = resolveTimer.Elapsed.TotalMilliseconds
};
}
}
}
Loading