-
Notifications
You must be signed in to change notification settings - Fork 6
/
MultipleReturnsIntBenchmarks.tt
62 lines (57 loc) · 2.32 KB
/
MultipleReturnsIntBenchmarks.tt
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
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from the "MultipleReturnsIntBenchmarks.tt" T4 Text Template.
// </auto-generated>
//------------------------------------------------------------------------------
<# int maxsize = 7; #>
using BenchmarkDotNet.Attributes;
using System;
using System.Runtime.CompilerServices;
namespace MultipleReturnsTechniques
{
public class MultipleReturnsIntBenchmarks
{
[Benchmark]
public void return_int_1() => _ = return_int_1_method();
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public int return_int_1_method()
{
return new int();
}
<# for (int i = 1; i <= maxsize; i++) { #>
[Benchmark]
public void out_int_<#= i #>() => out_int_<#= i #>_method(<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"out _")) #>);
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public void out_int_<#= i #>_method(<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"out int _{x}")) #>)
{
<# for (int j = 1; j <= i; j++) { #>
_<#= j #> = new int();
<# } #>
}
[Benchmark]
public void tuple_int_<#= i #>() => _ = tuple_int_<#= i #>_method();
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public Tuple<<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"int")) #>> tuple_int_<#= i #>_method()
{
return new Tuple<<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"int")) #>>(
new int()<# for (int j = 1; j < i; j++) { #>,
new int()<# } #>);
}
[Benchmark]
public void valuetuple_int_<#= i #>() => _ = valuetuple_int_<#= i #>_method();
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public ValueTuple<<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"int")) #>> valuetuple_int_<#= i #>_method()
{
return new ValueTuple<<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"int")) #>>(
new int()<# for (int j = 1; j < i; j++) { #>,
new int()<# } #>);
}
<# } #>
}
}