Hi everybody-
There is a question posted by Rod Kemp in regards to performance benchmarks used for both algorithms (see Alternate 4). The sample code snippet, pertinent to the "ToggleCaseByJohn" algorithm is as follows:
DateTime dt = DateTime.Now;
for (Int64 i = 0; i < 100001; i++)
{
TextBox2.Text = ToggleCaseByJohn(TextBox2.Text);
}
TimeSpan ts = DateTime.Now - dt;
double dur = (double)ts.Milliseconds / 100;
Label3.Text = dur.ToString() + " us";
This technique does not provide the "academic precision' of testing, but rather gives just a first order approximation with adequate accuracy pertinent to this task. Sure thing, more sophisticated benchmarks procedures could be constructed if necessary, but this one could do the job as specified (for example, instead of using the function call the body of the algorithm could be encapsulated within the code snippet shown above). Also, note that the number of iteration is selected as 100001: it should be odd number in order to see the string visually "toggled", because the even number will return the string to the original state.
Best regards,
Alexander Bell
PPS. On a separate note: suggested Alternate 7 is JUST WRONG because suggested "simplified" version:
char.IsUpper(c) ? char.ToLower(c) : c
is not the equivalent of original:
char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c)
As you can see, that "simplified" Alternate 7 version does not convert Lower Case into Upper; it only converts Upper-to-Lower.