-
-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathPayloadColumn.cs
More file actions
65 lines (50 loc) · 1.56 KB
/
PayloadColumn.cs
File metadata and controls
65 lines (50 loc) · 1.56 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using Perfolizer.Metrology;
namespace Benchmark.BenchmarkNetUtilities;
public class PayloadColumnAttribute : ColumnConfigBaseAttribute
{
public PayloadColumnAttribute()
: base(new PayloadColumn())
{
}
}
public class PayloadColumn : IColumn
{
public string Id => nameof(PayloadColumn);
public string ColumnName => "Payload";
public bool AlwaysShow => true;
public ColumnCategory Category => ColumnCategory.Custom;
public int PriorityInCategory => 0;
public bool IsNumeric => true;
public UnitType UnitType => UnitType.Size;
public string Legend => "Payload size";
public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
{
var methodInfo = benchmarkCase.Descriptor.WorkloadMethod;
if (methodInfo.ReturnType == typeof(byte[]))
{
var instance = Activator.CreateInstance(benchmarkCase.Descriptor.Type);
var result = (byte[])methodInfo.Invoke(instance, null)!;
return new SizeValue(result.LongLength).ToString();
}
else
{
return "-";
}
}
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style)
{
return GetValue(summary, benchmarkCase);
}
public bool IsAvailable(Summary summary)
{
return true;
}
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase)
{
return false;
}
}