Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A more literal translation (using lambdas instead of a native for loop):

   using System;
   using System.Diagnostics;

   namespace testspeed
   {
   	public static class Extensions {
   		public delegate void Action();
   		public static void Times (this int numTimes, Action action)
   		{
   			for (var i = 0; i < numTimes; i++) {
   				action ();
   			}
   		}
   	}
   	class MainClass
   	{
   		public static void Main (string[] args)
   		{
   			var sw = Stopwatch.StartNew();
   			var x = 0;
   			1000000.Times (() => x += 1);
			
   			Console.WriteLine ("{0} in {1} ms", x, sw.ElapsedMilliseconds);
			
   			Console.ReadKey ();
   		}
   	}
   }

and it outputs 4 ms. Mono in debug mode on a 3.2 GHz Intel Core i3. For comparison, the parent's ruby code runs in 80ms with Ruby 1.9.2. Big difference, but not quite as bad. I don't know why though?


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: