4 ms·
C# definitely does not take 1ms to look up something in a hash map. Perhaps 1us (microsecond) in a horrible example if the virtual hash code has a slow algorith
by cpurdy 4y ago
C# definitely does not take 1ms to look up something in a hash map. Perhaps 1us (microsecond) in a horrible example if the virtual hash code has a slow algorithm and doesn't cache the result.
Regardless, the benefit of not using C++ is and always has been: Not having to use C++.
- _gabe_ 4y agoYep 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.