Created
December 21, 2021 17:42
-
-
Save tkapin/b8759b1b441e4a965fa7e26e2aa10d67 to your computer and use it in GitHub Desktop.
Concat benchmarks
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 Benchmarks; | |
public class Program | |
{ | |
public static int Main(string[] args) | |
{ | |
var summary = BenchmarkRunner.Run<ConcatImplementations>(); | |
return 0; | |
} | |
} | |
public class ConcatImplementations { | |
[Benchmark] | |
public void IEnumerableConcat() | |
{ | |
IEnumerable<string> args = new[] { "x", "y", "z" }; | |
args = new[] { "a", "b" }.Concat(args); | |
// materialize | |
_ = args.ToArray(); | |
} | |
[Benchmark] | |
public void ListInsertRange() | |
{ | |
List<string> args = new() { "x", "y", "z" }; | |
args.InsertRange(0, new[] { "a", "b" }); | |
// convert | |
_ = args.ToArray(); | |
} | |
} |
Author
tkapin
commented
Dec 21, 2021
Method | Mean | Error | StdDev |
---|---|---|---|
IEnumerableConcat | 157.4 ns | 3.14 ns | 4.79 ns |
ListInsertRange | 110.6 ns | 2.20 ns | 3.01 ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment