Friday, November 26, 2004
Refactoring hell
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...
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 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.