# Wednesday, June 25, 2008
« Useful Tool | Main | Exception Performance Part 2 »
Exception Performance Part 1

One area where IKVM performance is much worse than HotSpot is in throwing and catching exceptions. This blog is the first of three that will look into why this is the case.

We start out with two microbenchmarks to highlight the differences.


public class ExceptionPerf1 {
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
      try {
      catch (NumberFormatException x) {
    long end = System.currentTimeMillis();
    System.out.println(end - start);


using System;

class ExceptionPerf1 {
  public static void Main(string[] args) {
    int start = Environment.TickCount;
    for (int i = 0; i < 100000; i++) {
      try {
        throw new Exception();
      catch (Exception) {
    int end = Environment.TickCount;
    Console.WriteLine(end - start);


      HotSpot 1.6 x86     .NET 1.1 SP1     .NET 2.0 SP1 x86     Mono 1.9 x86
Java* 111 14743 3590 537
C#   11139 2605 187

*.NET/Mono results with IKVM 0.36

This shows that the situation on the CLR is pretty bad. If you care about exception throwing performance, please complain to Microsoft instead of to me. Although I expect that they'll tell you not to throw so many exceptions. ;-)

On the next episode we'll see that the above microbenchmark is actually a best case scenario for IKVM and we'll see how things can get much worse...

Wednesday, June 25, 2008 12:40:19 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [3]
Wednesday, June 25, 2008 4:22:52 PM (W. Europe Daylight Time, UTC+02:00)
Well: You should not throw so many exceptions ;)

Afaik this can be somewhat of a problem. As you said: In normal .Net you never need to raise an exception in normal code flow. However in Java this is quite common.

Interested to see the second part ;)
Wednesday, June 25, 2008 5:25:30 PM (W. Europe Daylight Time, UTC+02:00)
Perhaps the problem come from creating the Exception.

Have you play the test with an Exception created outside the for loop ?

Sunday, July 20, 2008 6:14:07 AM (W. Europe Daylight Time, UTC+02:00)
Wow i never thought mono would have such performance!

Btw i only did .net sofar, i had to google for the answer to your anti spam question :)
Comments are closed.