Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Branchmark for https://www.meziantou.net/2019/03/04/some-performance-tricks-with-net-strings
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace BranchmarkString
{
[CoreJob]
[MemoryDiagnoser, DisassemblyDiagnoser(printAsm: true, printSource: true)]
[RankColumn]
public class Benchmark
{
private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
private static readonly char[] _encode32CharsArray = "0123456789ABCDEFGHIJKLMNOPQRSTUV".ToCharArray();
private readonly long _id = DateTime.UtcNow.Ticks;
[Benchmark(Baseline = true)]
public unsafe string V1()
{
var id = _id;
char* buffer = stackalloc char[13];
buffer[0] = _encode32Chars[(int)(id >> 60) & 31];
buffer[1] = _encode32Chars[(int)(id >> 55) & 31];
buffer[2] = _encode32Chars[(int)(id >> 50) & 31];
buffer[3] = _encode32Chars[(int)(id >> 45) & 31];
buffer[4] = _encode32Chars[(int)(id >> 40) & 31];
buffer[5] = _encode32Chars[(int)(id >> 35) & 31];
buffer[6] = _encode32Chars[(int)(id >> 30) & 31];
buffer[7] = _encode32Chars[(int)(id >> 25) & 31];
buffer[8] = _encode32Chars[(int)(id >> 20) & 31];
buffer[9] = _encode32Chars[(int)(id >> 15) & 31];
buffer[10] = _encode32Chars[(int)(id >> 10) & 31];
buffer[11] = _encode32Chars[(int)(id >> 5) & 31];
buffer[12] = _encode32Chars[(int)id & 31];
return new string(buffer, 0, 13);
}
[Benchmark]
public string V2()
{
var id = _id;
Span<char> buffer = stackalloc char[13];
buffer[0] = _encode32Chars[(int)(id >> 60) & 31];
buffer[1] = _encode32Chars[(int)(id >> 55) & 31];
buffer[2] = _encode32Chars[(int)(id >> 50) & 31];
buffer[3] = _encode32Chars[(int)(id >> 45) & 31];
buffer[4] = _encode32Chars[(int)(id >> 40) & 31];
buffer[5] = _encode32Chars[(int)(id >> 35) & 31];
buffer[6] = _encode32Chars[(int)(id >> 30) & 31];
buffer[7] = _encode32Chars[(int)(id >> 25) & 31];
buffer[8] = _encode32Chars[(int)(id >> 20) & 31];
buffer[9] = _encode32Chars[(int)(id >> 15) & 31];
buffer[10] = _encode32Chars[(int)(id >> 10) & 31];
buffer[11] = _encode32Chars[(int)(id >> 5) & 31];
buffer[12] = _encode32Chars[(int)id & 31];
return new string(buffer);
}
[Benchmark]
public string V3()
{
return string.Create(13, _id, (buffer, id) =>
{
buffer[0] = _encode32Chars[(int)(id >> 60) & 31];
buffer[1] = _encode32Chars[(int)(id >> 55) & 31];
buffer[2] = _encode32Chars[(int)(id >> 50) & 31];
buffer[3] = _encode32Chars[(int)(id >> 45) & 31];
buffer[4] = _encode32Chars[(int)(id >> 40) & 31];
buffer[5] = _encode32Chars[(int)(id >> 35) & 31];
buffer[6] = _encode32Chars[(int)(id >> 30) & 31];
buffer[7] = _encode32Chars[(int)(id >> 25) & 31];
buffer[8] = _encode32Chars[(int)(id >> 20) & 31];
buffer[9] = _encode32Chars[(int)(id >> 15) & 31];
buffer[10] = _encode32Chars[(int)(id >> 10) & 31];
buffer[11] = _encode32Chars[(int)(id >> 5) & 31];
buffer[12] = _encode32Chars[(int)id & 31];
});
}
[Benchmark]
public string V4()
{
return string.Create(13, _id, (buffer, id) =>
{
buffer[12] = _encode32Chars[(int)id & 31];
buffer[11] = _encode32Chars[(int)(id >> 5) & 31];
buffer[10] = _encode32Chars[(int)(id >> 10) & 31];
buffer[9] = _encode32Chars[(int)(id >> 15) & 31];
buffer[8] = _encode32Chars[(int)(id >> 20) & 31];
buffer[7] = _encode32Chars[(int)(id >> 25) & 31];
buffer[6] = _encode32Chars[(int)(id >> 30) & 31];
buffer[5] = _encode32Chars[(int)(id >> 35) & 31];
buffer[4] = _encode32Chars[(int)(id >> 40) & 31];
buffer[3] = _encode32Chars[(int)(id >> 45) & 31];
buffer[2] = _encode32Chars[(int)(id >> 50) & 31];
buffer[1] = _encode32Chars[(int)(id >> 55) & 31];
buffer[0] = _encode32Chars[(int)(id >> 60) & 31];
});
}
[Benchmark]
public string V5()
{
return string.Create(13, _id, (buffer, id) =>
{
var encode32Chars = _encode32Chars;
buffer[12] = encode32Chars[(int)id & 31];
buffer[11] = encode32Chars[(int)(id >> 5) & 31];
buffer[10] = encode32Chars[(int)(id >> 10) & 31];
buffer[9] = encode32Chars[(int)(id >> 15) & 31];
buffer[8] = encode32Chars[(int)(id >> 20) & 31];
buffer[7] = encode32Chars[(int)(id >> 25) & 31];
buffer[6] = encode32Chars[(int)(id >> 30) & 31];
buffer[5] = encode32Chars[(int)(id >> 35) & 31];
buffer[4] = encode32Chars[(int)(id >> 40) & 31];
buffer[3] = encode32Chars[(int)(id >> 45) & 31];
buffer[2] = encode32Chars[(int)(id >> 50) & 31];
buffer[1] = encode32Chars[(int)(id >> 55) & 31];
buffer[0] = encode32Chars[(int)(id >> 60) & 31];
});
}
[Benchmark]
public string V6()
{
return string.Create(13, _id, (buffer, id) =>
{
var encode32CharsArray = _encode32CharsArray;
buffer[12] = encode32CharsArray[id & 31];
buffer[11] = encode32CharsArray[(id >> 5) & 31];
buffer[10] = encode32CharsArray[(id >> 10) & 31];
buffer[9] = encode32CharsArray[(id >> 15) & 31];
buffer[8] = encode32CharsArray[(id >> 20) & 31];
buffer[7] = encode32CharsArray[(id >> 25) & 31];
buffer[6] = encode32CharsArray[(id >> 30) & 31];
buffer[5] = encode32CharsArray[(id >> 35) & 31];
buffer[4] = encode32CharsArray[(id >> 40) & 31];
buffer[3] = encode32CharsArray[(id >> 45) & 31];
buffer[2] = encode32CharsArray[(id >> 50) & 31];
buffer[1] = encode32CharsArray[(id >> 55) & 31];
buffer[0] = encode32CharsArray[(id >> 60) & 31];
});
}
}
class Program
{
public static void Main()
{
var summary = BenchmarkRunner.Run<Benchmark>();
}
}
}
.NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
BranchmarkString.Benchmark.V6()
return string.Create(13, _id, (buffer, id) =>
^^^
{
^^^
var encode32CharsArray = _encode32CharsArray;
^^^
buffer[12] = encode32CharsArray[id & 31];
^^^
buffer[11] = encode32CharsArray[(id >> 5) & 31];
^^^
buffer[10] = encode32CharsArray[(id >> 10) & 31];
^^^
buffer[9] = encode32CharsArray[(id >> 15) & 31];
^^^
buffer[8] = encode32CharsArray[(id >> 20) & 31];
^^^
buffer[7] = encode32CharsArray[(id >> 25) & 31];
^^^
buffer[6] = encode32CharsArray[(id >> 30) & 31];
^^^
buffer[5] = encode32CharsArray[(id >> 35) & 31];
^^^
buffer[4] = encode32CharsArray[(id >> 40) & 31];
^^^
buffer[3] = encode32CharsArray[(id >> 45) & 31];
^^^
buffer[2] = encode32CharsArray[(id >> 50) & 31];
^^^
buffer[1] = encode32CharsArray[(id >> 55) & 31];
^^^
buffer[0] = encode32CharsArray[(id >> 60) & 31];
^^^
});
^^^
mov rsi,qword ptr [rcx+8]
mov rcx,7FFAA4804680h
mov edx,3
call coreclr!GC_Initialize+0x42b20
mov rcx,1C44DCC7268h
mov r8,qword ptr [rcx]
test r8,r8
jne M00_L00
mov rcx,7FFAA471C920h
call coreclr!GC_Initialize+0x42720
mov rdi,rax
mov rdx,1C44DCC7260h
mov rdx,qword ptr [rdx]
test rdx,rdx
je 00007ffa`a474312b
lea rcx,[rdi+8]
call coreclr!GC_Initialize+0x41280
mov rdx,7FFAA47422B8h
mov qword ptr [rdi+18h],rdx
mov rcx,1C44DCC7268h
mov rdx,rdi
call coreclr!GC_Initialize+0x41250
mov r8,rdi
M00_L00
mov ecx,0Dh
mov rdx,rsi
mov rax,7FFAA4723BD8h
BranchmarkString.Benchmark+<>c.b__3_0(System.Span`1, Int64)
var encode32CharsArray = _encode32CharsArray;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rcx,7FFAA4804680h
mov edx,1
call coreclr!GC_Initialize+0x42b20
mov rax,1C44DCC7258h
mov rax,qword ptr [rax]
buffer[12] = encode32CharsArray[id & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,0Ch
jbe 00007ffa`a4743488
mov rdx,rsi
and rdx,1Fh
mov ecx,dword ptr [rax+8]
movsxd rcx,ecx
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+18h],dx
buffer[11] = encode32CharsArray[(id >> 5) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,5
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+16h],dx
buffer[10] = encode32CharsArray[(id >> 10) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,0Ah
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+14h],dx
buffer[9] = encode32CharsArray[(id >> 15) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,0Fh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+12h],dx
buffer[8] = encode32CharsArray[(id >> 20) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,14h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+10h],dx
buffer[7] = encode32CharsArray[(id >> 25) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,19h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Eh],dx
buffer[6] = encode32CharsArray[(id >> 30) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,1Eh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Ch],dx
buffer[5] = encode32CharsArray[(id >> 35) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,23h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Ah],dx
buffer[4] = encode32CharsArray[(id >> 40) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,28h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+8],dx
buffer[3] = encode32CharsArray[(id >> 45) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,2Dh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+6],dx
buffer[2] = encode32CharsArray[(id >> 50) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,32h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+4],dx
buffer[1] = encode32CharsArray[(id >> 55) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rdx,rsi
sar rdx,37h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+2],dx
buffer[0] = encode32CharsArray[(id >> 60) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sar rsi,3Ch
mov rdx,rsi
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a4743488
movzx eax,word ptr [rax+rdx*2+10h]
mov word ptr [rdi],ax
});
^
add rsp,20h
.NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
BranchmarkString.Benchmark.V7()
return string.Create(13, _id, (buffer, id) =>
^^^
{
^^^
var encode32CharsArray = _encode32CharsArray;
^^^
buffer[0] = encode32CharsArray[(id >> 60) & 31];
^^^
buffer[1] = encode32CharsArray[(id >> 55) & 31];
^^^
buffer[2] = encode32CharsArray[(id >> 50) & 31];
^^^
buffer[3] = encode32CharsArray[(id >> 45) & 31];
^^^
buffer[4] = encode32CharsArray[(id >> 40) & 31];
^^^
buffer[5] = encode32CharsArray[(id >> 35) & 31];
^^^
buffer[6] = encode32CharsArray[(id >> 30) & 31];
^^^
buffer[7] = encode32CharsArray[(id >> 25) & 31];
^^^
buffer[8] = encode32CharsArray[(id >> 20) & 31];
^^^
buffer[9] = encode32CharsArray[(id >> 15) & 31];
^^^
buffer[10] = encode32CharsArray[(id >> 10) & 31];
^^^
buffer[11] = encode32CharsArray[(id >> 5) & 31];
^^^
buffer[12] = encode32CharsArray[id & 31];
^^^
});
^^^
mov rsi,qword ptr [rcx+8]
mov rcx,7FFAA47E4680h
mov edx,3
call coreclr!GC_Initialize+0x42b20
mov rcx,27E90007270h
mov r8,qword ptr [rcx]
test r8,r8
jne M00_L00
mov rcx,7FFAA46FC920h
call coreclr!GC_Initialize+0x42720
mov rdi,rax
mov rdx,27E90007260h
mov rdx,qword ptr [rdx]
test rdx,rdx
je 00007ffa`a472312b
lea rcx,[rdi+8]
call coreclr!GC_Initialize+0x41280
mov rdx,7FFAA47222C0h
mov qword ptr [rdi+18h],rdx
mov rcx,27E90007270h
mov rdx,rdi
call coreclr!GC_Initialize+0x41250
mov r8,rdi
M00_L00
mov ecx,0Dh
mov rdx,rsi
mov rax,7FFAA4703BD8h
BranchmarkString.Benchmark+<>c.b__4_0(System.Span`1, Int64)
var encode32CharsArray = _encode32CharsArray;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov rcx,7FFAA47E4680h
mov edx,1
call coreclr!GC_Initialize+0x42b20
mov rax,27E90007258h
mov rax,qword ptr [rax]
buffer[0] = encode32CharsArray[(id >> 60) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,0
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,3Ch
and rdx,1Fh
mov ecx,dword ptr [rax+8]
movsxd rcx,ecx
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi],dx
buffer[1] = encode32CharsArray[(id >> 55) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,1
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,37h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+2],dx
buffer[2] = encode32CharsArray[(id >> 50) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,2
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,32h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+4],dx
buffer[3] = encode32CharsArray[(id >> 45) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,3
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,2Dh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+6],dx
buffer[4] = encode32CharsArray[(id >> 40) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,4
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,28h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+8],dx
buffer[5] = encode32CharsArray[(id >> 35) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,5
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,23h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Ah],dx
buffer[6] = encode32CharsArray[(id >> 30) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,6
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,1Eh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Ch],dx
buffer[7] = encode32CharsArray[(id >> 25) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,7
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,19h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+0Eh],dx
buffer[8] = encode32CharsArray[(id >> 20) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,8
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,14h
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+10h],dx
buffer[9] = encode32CharsArray[(id >> 15) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,9
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,0Fh
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+12h],dx
buffer[10] = encode32CharsArray[(id >> 10) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,0Ah
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,0Ah
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+14h],dx
buffer[11] = encode32CharsArray[(id >> 5) & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,0Bh
jbe 00007ffa`a47234e8
mov rdx,rsi
sar rdx,5
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx edx,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+16h],dx
buffer[12] = encode32CharsArray[id & 31];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmp ebx,0Ch
jbe 00007ffa`a47234e8
mov rdx,rsi
and rdx,1Fh
cmp rdx,rcx
jae 00007ffa`a47234e8
movzx eax,word ptr [rax+rdx*2+10h]
mov word ptr [rdi+18h],ax
});
^
add rsp,20h
BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17763.253 (1809/October2018Update/Redstone5)
Intel Core i5-6600 CPU 3.30GHz (Skylake), 1 CPU, 4 logical and 4 physical cores
.NET Core SDK=3.0.100-preview-009812
  [Host] : .NET Core 3.0.0-preview-27122-01 (CoreCLR 4.6.27121.03, CoreFX 4.7.18.57103), 64bit RyuJIT
  Core   : .NET Core 3.0.0-preview-27122-01 (CoreCLR 4.6.27121.03, CoreFX 4.7.18.57103), 64bit RyuJIT

Job=Core  Runtime=Core
Method Mean Error StdDev Median Ratio Allocated Memory/Op
Original 34.21 ns 0.4022 ns 0.3358 ns 34.24 ns 1.00 48 B
Span 33.86 ns 0.7916 ns 1.1096 ns 33.77 ns 1.01 48 B
String.Create 21.87 ns 0.5358 ns 0.9099 ns 22.15 ns 0.65 48 B
String.Create with closure 46.30 ns 0.6876 ns 0.6095 ns 46.30 ns 1.35 136 B
Reverse assignation 21.69 ns 0.5319 ns 1.0622 ns 21.59 ns 0.66 48 B
Use local 18.95 ns 0.4856 ns 1.1253 ns 18.98 ns 0.61 48 B
Remove explicit cast 17.85 ns 0.4687 ns 1.1410 ns 17.16 ns 0.56 48 B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.