Created
November 30, 2021 08:55
-
-
Save mstefarov/27dfed196ec63a5d73f3c6ce32df3c24 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
[MediumRunJob] | |
[MemoryDiagnoser] | |
public class ToTest | |
{ | |
Dictionary<string,IntPtr> stringKeys = new(); | |
Dictionary<TileKey,IntPtr> structKeys = new(); | |
public ToTest() | |
{ | |
for (int x = -4; x < 5; x++) | |
for (int y = -4; y < 5; y++) | |
for (int z = -4; z < 5; z++) | |
{ | |
stringKeys[$"{x}_{y}_{z}"] = IntPtr.Zero; | |
structKeys[new TileKey(x,y,z)] = IntPtr.Zero; | |
} | |
} | |
[Benchmark] | |
public IntPtr WithStringKeys() | |
{ | |
IntPtr temp = default; | |
for (int x = -4; x < 5; x++) | |
for (int y = -4; y < 5; y++) | |
for (int z = -4; z < 5; z++) | |
temp = stringKeys[$"{x}_{y}_{z}"]; | |
return temp; | |
} | |
[Benchmark] | |
public IntPtr WithStructKeys() | |
{ | |
IntPtr temp = default; | |
for (int x = -4; x < 5; x++) | |
for (int y = -4; y < 5; y++) | |
for (int z = -4; z < 5; z++) | |
temp = structKeys[new TileKey(x,y,z)]; | |
return temp; | |
} | |
public readonly record struct TileKey(double X, double Y, double Z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment