My Twitter Page

So I joined the revolution into the new internet fad Twitter recently, and although I’m having trouble with some bugs (I think…) I’m having fun reading other people’s profiles.
My page is http://twitter.com/Codesleuth - followers welcome :)

DataRow[DataColumn] performance enhancements

Since the system I work on performs about 1000 DataTable specific manipulations per minute, I’ve been going through and working out some ways to speed it up that little bit more. Take the following code:

DataTable myData = new DataTable();
myData.ReadXml("myxml.xml");
if (myData.Rows[0].IsNull("column1"))
    return null;
else
    return myData.Rows[0]["column1"];

The obvious performance improvement here is to first pull out the column index from the DataTable and then also pull out the row you need. You would end up with something like this:

DataTable myData = new DataTable();
myData.ReadXml("myxml.xml");

DataRow row = myData.Rows[0];
int col = myData.Columns.IndexOf("column1");

if (col == -1)
    throw new Exception("The column 'column1' was not found.");

if (row.IsNull(col))
    return null;
else
    return row[col];

I first changed my code to work in this way but I was thinking to myself that the DataRow will still have to perform an index pull from its internal collection even when using the verified index for the column. Another way of doing this would be to pull out the DataColumn and use that in the place of the column index, but I had no idea what would be faster. So I fired up Reflector and took a look at the Int32 version of the index lookup:

public object this[int columnIndex]
{
    get
    {
        DataColumn column = this._columns[columnIndex];
        int defaultRecord = this.GetDefaultRecord();
        return column[defaultRecord];
    }
    set
    {
        DataColumn column = this._columns[columnIndex];
        this[column] = value;
    }
}

As you can see, internally the lookup finds the DataColumn first anyway, which means it would be faster for us to get the DataColumn in our own code first as we reference it twice. So our new code becomes:

DataTable myData = new DataTable();
myData.ReadXml("myxml.xml");

DataRow row = myData.Rows[0];
DataColumn col = myData.Columns["column1"];

if (col == null)
    throw new Exception("The column 'column1' was not found.");

if (row.IsNull(col))
    return null;
else
    return row[col];

This is a very tiny performance improvement, but every little helps when it’s used many times a second.

Snoutbreak 09 Media Pandemic

You’ve probably caught a glimpse of the ‘pandemic’ ‘outbreak’ of swine influenza that is doing the rounds in the media at the moment.
I thought I would contribute to the (excuse the pun) tripe that we’re all faced with and raise a point we’re all thinking: this is media hype.

Look at any news network, paper, or blog roll, and you will find comments that show there is no real need for this particular piece of news to be escalated this far.

I loved this Daily Show video, which summarises all that is stupid about the media:

The Daily Show With Jon Stewart M - Th 11p / 10c
Snoutbreak ‘09 - The Last 100 Days
thedailyshow.com
Daily Show
Full Episodes
Economic Crisis First 100 Days

If you’re looking for information, go to Effect Measure. Otherwise, laugh it off like the rest of us.

Cut Copy Are Awesome

I’m obsessed with another band again… (I know, I’m sorry, I can’t help it)

Please head on over to their Last.FM page and sample a few of their tracks such as Lights & Music or So Haunted. I’ve been listening to the In Ghost Colours album over and over and it’s not yet boring to me (which is unusual as this takes no effort for most bands).

I can’t describe exactly why I like them so much, but it has to do a bit with the Daft Punk-esque style meeting down-tempo 80’s style tripping synth.

Check out this video: