Archive for the 'Open Source' Category

February
7th 2009
A Debug Stopwatch (In C#)

Posted under Open Source & Performance

Time is of the utmost importance to almost any performance test, but, in .net, it can require a bit of scaffolding code. A triplet of C# classes can make short work of measuring performance, and of collating and persisting the results, in a handy XML format.

In the wild, this is often done with code similar to the following:

   Stopwatch sw = new Stopwatch();

   sw.Start();
   // Do some work here
   sw.Stop();

   Debug.WriteLine(sw.Elapsed.TotalMilliseconds.ToString();

This is hardly the end of the world, but it’s a bit cumbersome, especially over the course of many tests.  Perhaps a more natural construction would be:

   using (DebugStopwatch countIndexOf = new DebugStopwatch("IndexOf")) {
      // Do some work here
   }

… with the results being harvested later.  The literal text “IndexOf” can be replaced with any label that will be meaningful when you analyze the timing data.  Persistence of test results is accomplished through the magic of static classes. Continue Reading »

No Comments »

December
9th 2008
Normalizer of Web Pages, Qualifier of URLs

Posted under Open Source & Web

Relative paths look like /images/filename.jpeg, explaining the relationship between the current location and the resource.  Fully qualified paths are complete addresses, and look like http://domain.com/images/filename.jpg.

Sometimes you need to translate between the two.  Think of absolute urls as the third normal form of the web.

The complete solution has 138 lines in two classes, but this includes fetching the content from the internet.  Filling in a host name and path for each relative link is easy. You can download the full implementation

The juicy bits are below: Continue Reading »

1 Comment »