1 consider that the link that the stackoverflow thread refers to is using .net and not mono, you should test this first before assuming that it’s going to be faster. The obj.GetType() == typeof(SomeType) is optimized by the jit, but mono is a different jit than the .net jit… so it might not get optimized the same way.
2… really? How often are you testing the type of something that this small optimization is giving you some edge?
You think this is “critical code”? Cause I’d beg to say that if this is a bottle neck in your code… your critical code would be the fact you can’t write good code. Type checking like this shouldn’t be common.
You are right. I just made my own benchmark for different types and the conclusion is very interesting. Finally decided to use one of the methods to compare types, thanks!
Don’t get bogged down in this type of “optimisation”. It takes time away from you finishing your project and you don’t even know that it’s a problem.
Code that looks sub-optimal to a programmer’s eye is often just fine as far as your computer is actually concerned because there’s often bigger bottlenecks elsewhere in code or design, or because you don’t actually have a performance issue in the first place and therefore all optimisation is moot.
Measure before you optimise, and only bother to optimise where the measurements show you’re actually wasting resources.