Friday, November 26, 2004

When you're banging your head against that wall...

...it's amazing what a quick visit to the gym can do to clear your mind ;-)

Refactoring hell

Arrgggh! I am stuck in refactoring hell with the data access layer code generator addin for visual studio I wrote.

Isn't it funny how sometimes you think "I can make this so much better if I just change that..." and you end up in a world of pain :-/

Maybe listening to some smashing pumpkins will make it better...

Thursday, November 25, 2004

Life on the bleeding edge...

It's never easy thats for sure. I made the fateful decision the other day to upgrade my Mono installation. Why you say? Well I was seduced by the new language features, partial types, etc so I took the plunge and checked out the latest version from SVN.

Well, that went ok (surprisingly) and I now have Mono-1.1.2.99 installed on my machine. Unfortunately when I started Monodevelop things started to go distinctly astray :-/

I checked the latest version of Monodevelop out from SVN and after quite a few headaches (upgrading to gtk-sharp-2.0, trying to persuade gecko-sharp to compile against gtk-sharp-2.0... the list goes on!) I managed to get it to build, install and run!

Of course as soon as I opened a c# file it crashed... sigh.

Thursday, November 11, 2004

Date comparison with Null is super slow!

I was recently performance testing a logging component I'd written which simply logs entries to text file when I stumbled on a performance bottle neck I'd never come accross before.

I wrote the following simple test:

System.Diagnostics.Debug.WriteLine("Starting 10000 logs entries at: " + DateTime.Now.TimeOfDay.ToString());

for(int i = 0; i < 10000; i++)
    Logger.Instance.CreateLogEntry("New entry number " + i.ToString());

System.Diagnostics.Debug.WriteLine("Finished writing entries at: " + DateTime.Now.TimeOfDay.ToString());

This managed 10,000 writes in 0.5 secs. I then added the following line into the CreateLogEntry method:

if (_logDate.Date != DateTime.Now.Date)

I was using this check to see if the date had rolled over to the next day (This component is used by a windows serivce that runs continuously and creates a new log file each day). When I re-ran my test imagine my horror to see that the 10,000 writes was now taking 5 mins and 19 secs!

For a moment I wondered how date comparisons in .NET could possible be so slow, and it was then that I realised I was never initialising _logDate, so each time the CreateLogEntry method was called I was doing a comparison between DateTime.Now.Date and null. After fixing my mistake I was back to doing 10,000 writes in 0.53 secs... much better!

It did teach me an important leason though. Comparison with null is very expensive and should be avoided at all costs if performance is a priority.