Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed class Tester : Tester<object>
- {
- private readonly Action action;
- public Tester(Action action, int times)
- {
- this.action = action;
- this.times = times;
- }
- new public async Task<long> Run()
- {
- var stopWatch = new Stopwatch();
- long timeSpent = 0;
- await Task.Run(() =>
- {
- for (int i = 0; i < times; i++)
- {
- stopWatch.Start();
- action();
- stopWatch.Stop();
- timeSpent += stopWatch.ElapsedMilliseconds;
- }
- });
- return timeSpent / times;
- }
- }
- class Tester<T>
- {
- private readonly Action<T> action;
- private readonly Func<T> seed;
- private readonly bool useSeed;
- protected int times;
- protected Tester() { }
- public Tester(Action<T> action, int times, Func<T> seed)
- {
- this.action = action;
- this.times = times;
- this.seed = seed;
- useSeed = true;
- }
- public async Task<long> Run()
- {
- var stopWatch = new Stopwatch();
- long timeSpent = 0;
- await Task.Run(() =>
- {
- for (int i = 0; i < times; i++)
- {
- var seedValue = seed();
- stopWatch.Start();
- action(seedValue);
- stopWatch.Stop();
- timeSpent += stopWatch.ElapsedMilliseconds;
- }
- });
- return timeSpent/times;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement