Just sharing some of my inconsequential lunch conversations with you... RSS  

Tuesday, June 16, 2009

Cool StopWatch helper

I was browsing some code when I hit the following:

        static TimeSpan Time(Action action)
{
var sw = Stopwatch.StartNew();
action();
return sw.Elapsed;
}


Not that this code is somewhat extraordinary, the beauty of this is precisely how simply we can write this code nowadays:



    TimeSpan elapsed = Time(() => Matrix.Multiply(matA, matB, matC));


I just can’t stop being amazed with simplicity :)

1 comment:

tiago said...

Cool.

I really want to start using lambdas but I keep forgetting about them when there's a change to use them.

Development Catharsis :: Copyright 2006 Mário Romano