RSPEC-6602's benchmark doesn't include Array.Find and ImmutableList.Find
S6602 tells you to replace calls to Enumerable.FirstOrDefault with calls to a "Find" method but its benchmark only includes FirstOrDefault and List<T>.Find despite the rule also applying to Array and ImmutableList.
Given the implementation of Array.Find<T> looks pretty similar to List<T>.Find I don't expect the rule to become irrelevant for arrays after updating the benchmark but, to someone that only looks at the rule's documentation, it would prove Array.Find<T> is also better than Enumerable.FirstOrDefault. About ImmutableList I couldn't find the implementation after giving a quick look to the class but I assume it's also faster than FirstOrDefault 🤷♂️
Hey @nalka0 ,
First of all, let me say that I happy you took interest in our benchmarking data! This is a new feature we introduced in performance-intensive rules, so it is very helpful to get feedback on it.
About your suggestion, I am a bit on the fence. On the one hand, I like the "completion" your idea offers, having everything in plain sight. On the other hand, I am afraid the metrics table will become too bulky and people will just not bother reading it.
Right now, the logic is "here is part of the benchmarks we ran, and you can trust us for the rest". ...but I can understand someone wanting full visibility. :)
I will raise this internally and try to make these benchmark tables look as consistent as possible.
Thanks a lot, Greg
Nick Chapsas recently pointed-out in this video that in .net9 (C#13) the opposite is true (FirstOrDefault is faster). I'm not familiar with how Sonar benchmarks stuff, are the benchmarks run for every release of .net and results for each version used separately, or is it generalized? My question is: Should I expect to receive the opposite warnings from sonar when I upgrade to .net9 in the future?
That's a good point @leocb . Truth is, we don't have a strict procedure in place for this kind of thing. I will discuss it with my team internally and see that we re-run the benchmarks and discuss about what to do with the rules based on the results.
Thanks!
Fixed in SonarSource/rspec/pull/4438