Internet Explorer 7 comes with build in web search from the toolbar, just like Firefox have had for years now. The cool thing about it is that you can offer your visitors to add your blog search to the different providers like MSN Search and Google. That’s because IE7 supports the OpenSearch format, which is a simple XML file that you can link to from within the <head> of your webpages. All you need is a website with an internal search engine just like the one on this blog.

To make it work you have to create an XML file in the correct OpenSearch format and upload it to your web server. Use this simple online tool for generating a correct XML file. Then add this line to the <head> of your webpages:

<link title="Title of blog" type="application/opensearchdescription+xml" rel="search" href="http://www.domain.com/provider.xml">

That’s it! Now, every time a visitor comes by using IE7 the search button lights up in an orange color indicating that your site has a compatible search provider. The visitor can then use it right away by choosing it on the dropdown list, or add it permanently to the list of search providers to use whenever and not just when visiting your blog.

Here is my OpenSearch XML file. Notice that it contains the Unicode character &#46; in order to make it validate the dot in .NET slave.

I don’t know if it is going to be used by a great number of people, we’ll probably have to wait for the final release of IE7 to find out. In the meantime, I find no reason why not to implement this simple little feature with such great potential.

Have you ever considered how well a regular if/else-statement performs? I haven’t, but after watching this Channel9 video I wanted to test it.

In the video, Brian Beckman explains that the order of the statements is important to the performance. In other words; the most likely statement to succeed should be the first. Let’s take a look at a simple method with an if/else statement. As you can see, it doesn’t do much, but that’s exactly what we want in order to test the if/else-statement.

  private bool RunIf(string input)

  {

    if (input == "hello")

      return true;

    else if (input == "jelly")

      return true;

    else

      return true;

  }

If the theory is correct, it should be faster to pass in “hello” than “jelly”, which again would be faster than a random third string. To test this, we need a method that calls RunIf() a lot of times in order to measure it.
 

  private void Test()

  {

    DateTime start = DateTime.Now;

 

    for (int i = 0; i < 100000000; i++)

    {

      RunIf("hello");

    }

 

    TimeSpan span = DateTime.Now.Subtract(start);

    Console.Write(span.TotalMilliseconds);

  }

Results

I did three tests. In the first I passed “hello” to the RunIf, the second “jelly” and the third “other” – all 5 letter words for consistency. Here’s the total runtime in milliseconds for each of the three tests.

1. “hello”: 1546 milliseconds
2. “jelly”: 3687 milliseconds
3. “other”: 4453 milliseconds

It is actually more than twice as fast to run the first if-statement as having to move into the “if else” statement.

So, what can we use this information for? Probably not much, because I had to make a hundred million iterations in the Test() method just to be able to measure the result. Unless of course you have an application that does just that, then this is merely a little information for your consideration.

Or maybe we can go as far as to say that it would improve the performance of your if/else-statements to run the first if-statement more often than the else statement.