4 ms·
Yep you are correct, I was mis-remembering quite a bit. I just re-ran the tests using BenchmarkDotNet and C# takes 124 nanoseconds on average, which is still 10
by _gabe_ 4y ago
Yep you are correct, I was mis-remembering quite a bit. I just re-ran the tests using BenchmarkDotNet and C# takes 124 nanoseconds on average, which is still 100x slower and a considerable difference, but not orders of magnitude difference :)
C# benchmarks on my machine. FastFindRecipe just does a hash set lookup, it looks like this:
private static readonly HashSet<CraftingRecipe> FastList = new HashSet<CraftingRecipe>(new CraftingComparer());
public static CraftingRecipe? FastFind(CraftingRecipe r) => FastList.TryGetValue(r, out var res) ? res : null;
| Method | Mean | Error | StdDev | Min | Max |
|--------------- |---------:|--------:|--------:|---------:|---------:|
| FindRecipe | 315.2 ns | 1.17 ns | 1.09 ns | 313.6 ns | 317.4 ns |
| FastFindRecipe | 124.5 ns | 0.23 ns | 0.21 ns | 124.1 ns | 124.9 ns |
- avgcorrection 4y ago> , which is still 100x slower and a considerable difference, but not orders of magnitude difference :) Two orders of magnitude.