Last active
November 25, 2019 18:47
-
-
Save Mrnikbobjeff/5bd549db39f56d3f63347574cf60f8b5 to your computer and use it in GitHub Desktop.
It can allocate more :O
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace AllocationBenchmark | |
{ | |
[DryCoreJob, DryClrJob] | |
[MemoryDiagnoser] | |
public class FormatAllocation | |
{ | |
[Benchmark] | |
public string FormatThreeParameters() | |
{ | |
return $"a{1}a{2}a{3}a"; | |
} | |
[Benchmark] | |
public string FormatStringThreeParameters() | |
{ | |
return $"b{1.ToString()}b{2.ToString()}b{3.ToString()}b"; | |
} | |
[Benchmark] | |
public string FormatOneParameter() | |
{ | |
return $"a{1}a{2}a{3}a"; | |
} | |
[Benchmark] | |
public string FormatStringOneParameter() | |
{ | |
return $"b{1.ToString()}b{2.ToString()}b{3.ToString()}b"; | |
} | |
[Benchmark] | |
public string FormatFourParameters() | |
{ | |
return $"a{1}a{2}a{3}a{4}a"; | |
} | |
[Benchmark] | |
public string FormatStringFourParameters() | |
{ | |
return $"b{1.ToString()}b{2.ToString()}b{3.ToString()}b{4.ToString()}b"; | |
} | |
[Benchmark] | |
public string FormatThreeParametersL() | |
{ | |
return $"a{int.MaxValue}a{int.MaxValue}a{int.MaxValue}a"; | |
} | |
[Benchmark] | |
public string FormatStringThreeParametersL() | |
{ | |
return $"b{int.MaxValue.ToString()}b{int.MaxValue.ToString()}b{int.MaxValue.ToString()}b"; | |
} | |
[Benchmark] | |
public string FormatOneParameterL() | |
{ | |
return $"a{int.MaxValue}a{int.MaxValue}a{int.MaxValue}a"; | |
} | |
[Benchmark] | |
public string FormatStringOneParameterL() | |
{ | |
return $"b{int.MaxValue.ToString()}b{int.MaxValue.ToString()}b{int.MaxValue.ToString()}b"; | |
} | |
[Benchmark] | |
public string FormatFourParametersL() | |
{ | |
return $"a{int.MaxValue}a{int.MaxValue-1}a{int.MaxValue-2}a{int.MaxValue-3}a"; | |
} | |
[Benchmark] | |
public string FormatStringFourParametersL() | |
{ | |
return $"b{(int.MaxValue - 1).ToString()}b{(int.MaxValue - 2).ToString()}b{(int.MaxValue - 3).ToString()}b{(int.MaxValue - 3).ToString()}b"; | |
} | |
static void Main(string[] args) | |
{ | |
BenchmarkRunner.Run<FormatAllocation>(); | |
} | |
} | |
} |
Author
Mrnikbobjeff
commented
Nov 25, 2019
•
Method | Job | Runtime | Mean | Error | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|
FormatThreeParameters | DryClr | Clr | 621.9 us | NA | - | - | - | 8192 B |
FormatStringThreeParameters | DryClr | Clr | 595.6 us | NA | - | - | - | 8192 B |
FormatOneParameter | DryClr | Clr | 780.5 us | NA | - | - | - | 8192 B |
FormatStringOneParameter | DryClr | Clr | 538.4 us | NA | - | - | - | 8192 B |
FormatFourParameters | DryClr | Clr | 596.8 us | NA | - | - | - | 8192 B |
FormatStringFourParameters | DryClr | Clr | 557.7 us | NA | - | - | - | 8192 B |
FormatThreeParametersL | DryClr | Clr | 622.9 us | NA | - | - | - | 8192 B |
FormatStringThreeParametersL | DryClr | Clr | 529.0 us | NA | - | - | - | 8192 B |
FormatOneParameterL | DryClr | Clr | 536.2 us | NA | - | - | - | 8192 B |
FormatStringOneParameterL | DryClr | Clr | 523.2 us | NA | - | - | - | 8192 B |
FormatFourParametersL | DryClr | Clr | 502.0 us | NA | - | - | - | 8192 B |
FormatStringFourParametersL | DryClr | Clr | 556.1 us | NA | - | - | - | 8192 B |
FormatThreeParameters | DryCore | Core | 439.6 us | NA | - | - | - | 112 B |
FormatStringThreeParameters | DryCore | Core | 660.7 us | NA | - | - | - | 120 B |
FormatOneParameter | DryCore | Core | 411.1 us | NA | - | - | - | 112 B |
FormatStringOneParameter | DryCore | Core | 448.5 us | NA | - | - | - | 120 B |
FormatFourParameters | DryCore | Core | 646.2 us | NA | - | - | - | 192 B |
FormatStringFourParameters | DryCore | Core | 459.1 us | NA | - | - | - | 136 B |
FormatThreeParametersL | DryCore | Core | 520.4 us | NA | - | - | - | 168 B |
FormatStringThreeParametersL | DryCore | Core | 463.5 us | NA | - | - | - | 320 B |
FormatOneParameterL | DryCore | Core | 452.5 us | NA | - | - | - | 168 B |
FormatStringOneParameterL | DryCore | Core | 433.1 us | NA | - | - | - | 320 B |
FormatFourParametersL | DryCore | Core | 433.8 us | NA | - | - | - | 264 B |
FormatStringFourParametersL | DryCore | Core | 415.9 us | NA | - | - | - | 400 B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment