Performance of static methods vs instance methods

In theory, a static method should perform slightly better than an instance method, all other things being equal, because of the extra hidden this parameter. In practice, this makes so little difference that it’ll be hidden in the noise of various compiler decisions. (Hence two people could “prove” one better than the other with disagreeing … Read more

What is the relative performance difference of if/else versus switch statement in Java?

I totally agree with the opinion that premature optimization is something to avoid. But it’s true that the Java VM has special bytecodes which could be used for switch()’s. See WM Spec (lookupswitch and tableswitch) So there could be some performance gains, if the code is part of the performance CPU graph.

Session lock causes ASP.Net websites to be slow

If your page does not modify any session variables, you can opt out of most of this lock. <% @Page EnableSessionState=”ReadOnly” %> If your page does not read any session variables, you can opt out of this lock entirely, for that page. <% @Page EnableSessionState=”False” %> If none of your pages use session variables, just … Read more

Do try/catch blocks hurt performance when exceptions are not thrown?

Check it. static public void Main(string[] args) { Stopwatch w = new Stopwatch(); double d = 0; w.Start(); for (int i = 0; i < 10000000; i++) { try { d = Math.Sin(1); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } w.Stop(); Console.WriteLine(w.Elapsed); w.Reset(); w.Start(); for (int i = 0; i < 10000000; i++) { … Read more

Is the “*apply” family really not vectorized?

First of all, in your example you make tests on a “data.frame” which is not fair for colMeans, apply and “[.data.frame” since they have an overhead: system.time(as.matrix(m)) #called by `colMeans` and `apply` # user system elapsed # 1.03 0.00 1.05 system.time(for(i in 1:ncol(m)) m[, i]) #in the `for` loop # user system elapsed # 12.93 … Read more