Best Practices for String Comparison

I was interested in the efficiency of string comparison. For example, when performing a case-insensitive comparison, is it better to use the String.Equals method with StringComparison.InvariantCultureIgnoreCase, or the simple trick of converting both strings to upper- or lower-case? I found an MSDN article, New Recommendations for Using Strings in Microsoft .NET 2.0, that discusses all this and more.

In a nutshell:

  • Use an overload that takes the StringComparison enumeration
  • If you don’t care about the linguistic content, as in the majority of cases, use StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase for the best performance. An ordinal comparison runs the fastest because it compares bytes directly and applies no linguistic rule to compute the result.

Going back to my original question, using String.InvariantCultureIgnoreCase is not as efficient because while it specifies culture-independence, the strings are still compared in a linguistic sense. And when you normalize casing with String.ToUpperInvariant or String.ToLowerInvariant, the extra step means that the comparison is not as fast as using StringComparison.OrdinalIgnoreCase.

Missing Filter Web Parts in SharePoint

While creating a web part page I discovered that the Query String Filter web part was missing. In fact, none of the filter web parts was available. A search for “filter” revealed that the filter web parts belong to a site-level feature called BizAppsSiteTemplates. However, for some reason, this feature wasn’t activated. Furthermore, it had the Hidden attribute turned on so I couldn’t see it in the site feature list. I tried to manually install the feature using STSADM, but it turned out the feature was alread installed. So I activated it with STSADM:

stsadm -o activatefeature -name bizappssitetemplates -url http://moss2007/mysite

After that the filter web parts finally showed up in the Web Part Gallery.

Once you locate the DWP file for a web part, you can also upload it directly to the Web Part Gallery. But activating the parent feature is more efficient and elegant.

Switching on Strings in C++ and C

I was wondering what the performance hit of switching on strings was. This is interesting to know:

http://dotnetperls.com/string-switch

In C++ and C they only allow switching on integral values. I imagine in certain cases the compiler could make a jump statement which used the integer directly (maybe as part of the jump address, positioned relatively from the current one). That’s probably why it’s not allowed for character arrays or objects in general in C++. At least that’s my guess.

Another interesting link: http://blogs.msdn.com/cbrumme/archive/2003/04/22/51371.aspx

An interesting if unrelated link: http://blogs.ipona.com/james/archive/2008/05/23/Dangerous-Ideas-in-C-No.-1-A-Better-Switch.aspx

Refactoring XmlWriter

I found this link interesting: http://elegantcode.com/2009/06/19/refactoring-xmlwriter/

XmlWriter and XmlReader are convenient and one of the fastest ways of creating XML, but they are kind of ugly sometimes. I wrote a class that encapsulated these methods into XmlFilter, which makes it easy to change pieces of an XML file without writing the same scaffolding over and over again, and without using an XmlDocument (which is quite a bit slower and consumed more memory than I preferred.)

The next release of Officewriter should be significantly faster (roughly 2 to 4 times as fast, according to current benchmarks) than the 4.0 release for parsing Excel 2007 files. This is mostly because I replaced a section of code that used the XmlDocument with a custom written replacement which was more specific to my needs. I don’t think the .NET framework (at least parts of it) was written with performance in mind, but I’ll get into that in a later blog post.

The Two Kinds of Colocation Failover

The Two Kinds of Failovers

Active/Active
  • Pros
    • Global Load Balancing (GLB) supported
    • Automated fail over
      • Less down time
    • Automated or manual roll back to primary in most cases
  • Cons
    • (Generally) More expensive then active/passive fail over
    • Setup is more complex
  • Notes

Adding a Virtual Machine Host to SCVMM 2008

For the sake of saving space in the title, SCVMM stand for System Center Virtual Machine Manager. SCVMM is a Microsoft application used to centrally manage multiple Hyper-V enabled hosts and VMs.

Today was my first chance to have some hands on time with our SCVMM instance. I had a fairly simple task to accomplish, add a Windows 2008 virtual machine host to SCVMM.

To start, click add host from the action panel on the right hand side of SCVMM. I was able to easily find my virtual machine host using the integrated AD lookup tool, but the job created to add the host timed out shortly with an error 415:

Continue reading Adding a Virtual Machine Host to SCVMM 2008

How to Enable Debug Logs on Your Blackberry

Enabling debug logs on a blackberry device can help provide useful information when troubleshooting an issue.

Blackberry Storm

  1. Bring up the keyboard on your home screen by pressing the blackberry key followed by show keyboard.
  2. Hold the 123 button in until you see a small lock icon.
  3. Type in the following sequence “/”/

Other Blackberries (This hasn’t been tested on anything newer then the Curve.)

  1. On the home screen, hold down the ALT key and type the following sequence LGLG

Log display

  1. You can adjust the minimum log level under EventLogger Options by pressing the blackberry key followed by options. You can changing the level in the top drop down box.
  2. While still under EventLogger options, you can filter certain logged events by toggling them on and off.

How to save a copy of the debug log

With the EventLog screen open:

  1. Click the track wheel and select Copy Day’s Contents.
  2. Paste the contents into the body of an email and send the message to yourself.

How to Disable MDS-CS on a Per-User Basis

Any BES administrator who has migrated their BES environment from 4.1 to 5.0 can see the extensive changes made in the central blackberry management interface. I’ve found it difficult at times to find certain options in the new BAS console. Today, I was looking for the option to turn off MDS-CS for a specific user in other words I wanted to keep the user from browsing the internet/intranet from their blackberry. The MDS user component has been renamed External Services and can be found under the component information of a BES user account.

Reverse Polish Notation

My knowledge of reverse polish notation came in handy today. It’s weird how these things come up in real life and not just in an academic setting. Granted, not every college graduate deals with the Excel file format.

Excel’s formulas are stored in binary spreadsheet files in reverse polish notation, which makes sense. There aren’t usually numbers in the file which say how many arguments a function contains, so we have to know that in advance to be able to understand the formula. You evaluate the arguments of a formula before the formula itself, so the stack at the point of evaluating the formula itself should contain exactly the number of arguments the formula has. It’s elegant when it works, but it makes it difficult to figure out when you have an error (unlike in XML where everything has boundaries)

Usually, if you read in more arguments than are available, an exception is thrown, and if you read in too few, an exception is thrown when evaluation completes and you have extra tokens to read. You could theoretically read too few arguments at one point and too many at another and just have an invalid result, but that would require two errors happening simultaneously, which is (hopefully) improbable.

The “Big 3” Colocation Monthly Cost Factors

Below are the “Big 3” colocation cost factors that will make up the majority of your monthly bill

Space

Space is the proximity that you will occupy inside of the colocation facility. Space is billed by the amount of rack space you occupy. It can sold in multi 1U, shared, or private half/full rack(s) increments.

Bandwidth

Bandwidth is billed by megabits per second (Mbps) circuit (sometimes less) and can be served to your rack’s networking equipment over a variety of mediums (i.e. copper, fiber).

Colocation vendors typically offer two different billing methods: capped and burstable billing.

Blogged