Performance testing static methods versus instance methods

I was creating several static methods at work today and I started to wonder about how static methods perform versus instance methods. So I created a quick test, that simply calls a static method 5,000,000 times and an instance method the same number of times. Both methods are identical, they simply return true, but as you can see from the results, the static method executes 20-50% slower than the instance method.

To test for yourself, simply click the "Test Instance Method" button to run the instance method test, and then when it’s done you can click the button again to start the static method test. Your results for each test are displayed in the DataGrid. All times are represented in milliseconds.

You can view the source of this application here.

Get Adobe Flash player

Tags: , , ,