-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroArgumentsSource.cs
More file actions
35 lines (31 loc) · 1.21 KB
/
IntroArgumentsSource.cs
File metadata and controls
35 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Threading;
using BenchmarkDotNet.Attributes;
namespace BenchmarkDotNet.Samples
{
public class IntroArgumentsSource
{
[Benchmark]
[ArgumentsSource(nameof(Numbers))]
public double ManyArguments(double x, double y) => Math.Pow(x, y);
public IEnumerable<object[]> Numbers() // for multiple arguments it's an IEnumerable of array of objects (object[])
{
yield return new object[] { 1.0, 1.0 };
yield return new object[] { 2.0, 2.0 };
yield return new object[] { 4.0, 4.0 };
yield return new object[] { 10.0, 10.0 };
}
[Benchmark]
[ArgumentsSource(typeof(BenchmarkArguments), nameof(BenchmarkArguments.TimeSpans))] // when the arguments come from a different type, specify that type here
public void SingleArgument(TimeSpan time) => Thread.Sleep(time);
}
public class BenchmarkArguments
{
public IEnumerable<object> TimeSpans() // for single argument it's an IEnumerable of objects (object)
{
yield return TimeSpan.FromMilliseconds(10);
yield return TimeSpan.FromMilliseconds(100);
}
}
}