Skip to content

Instantly share code, notes, and snippets.

@mstefarov
Created November 30, 2021 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstefarov/27dfed196ec63a5d73f3c6ce32df3c24 to your computer and use it in GitHub Desktop.
Save mstefarov/27dfed196ec63a5d73f3c6ce32df3c24 to your computer and use it in GitHub Desktop.
[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