[Mono-devel-list] Performance w/ boxing

Ben Maurer 05mauben at hawken.edu
Thu Feb 19 08:11:12 EST 2004


Hey guys,

Today I posted a blog entry about the performance of boxing. Someone
posted that MS was a few times faster on the test. My first reaction was
that this was a GC problem, however given the nature of the test case,
the generational GC does not give MS much of an advantage. I am not
really sure what is up.

I would be interested if any of the runtime guys have any ideas about
how to speed this up. The code is below:

using System; 

class T { 
     const int iters = 10, value = 32; 
      
     public static int fib (int n) { 
          if (n < 2) return 1; 
          return fib (n-2) + fib (n-1); 
     } 
      
     public static object fib_box (object n) { 
          int nn = (int) n; 
          if (nn < 2) return 1; 
          return (int) fib_box (nn-2) + (int) fib_box (nn-1); 
     } 
      
     public static void Main () { 
          // jit everything, so we dont get funk 
          fib (1); 
          fib_box (1); 
          { DateTime foo = DateTime.Now; } 
           
          DateTime t1 = DateTime.Now; 
           
          for (int i = 0; i < iters; i ++) fib (value); 
           
          DateTime t2 = DateTime.Now; 
           
          for (int i = 0; i < iters; i ++) fib_box (value); 
           
          DateTime t3 = DateTime.Now; 
           
          Console.WriteLine ("NO BOXING  : {0}", t2 - t1); 
          Console.WriteLine ("WITH BOXING: {0}", t3 - t2); 
     } 
}

My results were:
NO BOXING  : 00:00:01.2031260
WITH BOXING: 00:00:59.2343780

Someone with windows tested and got:
C:\Playground\Mono>boxtest
NO BOXING : 00:00:02.7439456
WITH BOXING: 00:00:15.9729680

C:\Playground\Mono>mono boxtest.exe
NO BOXING : 00:00:03.6550000
WITH BOXING: 00:03:27.9590000




More information about the Mono-devel-list mailing list