Created
October 26, 2019 18:40
-
-
Save controlflow/41f3d5561b8f4ffcc71e05426f6054de to your computer and use it in GitHub Desktop.
This file contains 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
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.17763.805 (1809/October2018Update/Redstone5), VM=VMware | |
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores | |
[Host] : .NET Framework 4.8 (4.8.4018.0), X86 LegacyJIT | |
DefaultJob : .NET Framework 4.8 (4.8.4018.0), X86 LegacyJIT | |
| Method | Count | Mean | Error | StdDev | Rank | | |
|--------------- |------ |------------:|----------:|----------:|-----:| | |
| IntArray | 1000 | 260.9 ns | 3.25 ns | 3.04 ns | 1 | | |
| StringArray | 1000 | 3,372.6 ns | 25.71 ns | 22.79 ns | 4 | | |
| StringBoxArray | 1000 | 1,504.0 ns | 18.43 ns | 17.24 ns | 2 | | |
| IntArray | 10000 | 2,985.6 ns | 27.66 ns | 25.87 ns | 3 | | |
| StringArray | 10000 | 33,456.6 ns | 315.20 ns | 294.84 ns | 6 | | |
| StringBoxArray | 10000 | 14,966.4 ns | 127.60 ns | 119.36 ns | 5 | | |
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.17763.805 (1809/October2018Update/Redstone5), VM=VMware | |
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores | |
[Host] : .NET Framework 4.8 (4.8.4018.0), X64 RyuJIT | |
DefaultJob : .NET Framework 4.8 (4.8.4018.0), X64 RyuJIT | |
| Method | Count | Mean | Error | StdDev | Rank | | |
|--------------- |------ |------------:|----------:|----------:|-----:| | |
| IntArray | 1000 | 422.6 ns | 8.46 ns | 11.29 ns | 1 | | |
| StringArray | 1000 | 1,987.8 ns | 17.91 ns | 15.87 ns | 3 | | |
| StringBoxArray | 1000 | 1,721.7 ns | 22.09 ns | 19.59 ns | 2 | | |
| IntArray | 10000 | 4,146.9 ns | 34.87 ns | 32.61 ns | 4 | | |
| StringArray | 10000 | 19,900.7 ns | 181.12 ns | 169.42 ns | 6 | | |
| StringBoxArray | 10000 | 17,193.7 ns | 108.32 ns | 101.33 ns | 5 | |
This file contains 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; | |
public struct StringBox { | |
public string Value; | |
} | |
[RankColumn] | |
public class ArraysBenchmark { | |
private int[] intArray; | |
private string[] stringArray; | |
private StringBox[] stringBoxArray; | |
[Params(1000, 10000)] | |
public int Count; | |
[GlobalSetup] | |
public void Setup() { | |
intArray = new int[Count]; | |
stringArray = new string[Count]; | |
stringBoxArray = new StringBox[Count]; | |
} | |
[Benchmark] | |
public void IntArray() { | |
var array = intArray; | |
for (var index = 0; index < array.Length; index++) { | |
array[index] = 42; | |
} | |
} | |
[Benchmark] | |
public void StringArray() { | |
var array = stringArray; | |
for (var index = 0; index < array.Length; index++) { | |
array[index] = "42"; | |
} | |
} | |
[Benchmark] | |
public void StringBoxArray() { | |
var array = stringBoxArray; | |
for (var index = 0; index < array.Length; index++) { | |
array[index].Value = "42"; | |
} | |
} | |
} | |
public class Program { | |
public static void Main(string[] args) { | |
BenchmarkRunner.Run<ArraysBenchmark>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment