Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Comments

TimP TimP
  • Euan Garden - Tour of SQL Server team (Part IV)

    What's the estimated cost for the whole machine (Superdome + hard drives)?

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Out of my own curiosity, I did a few tests to test performance. I'm no performance test guru, but what I did was use an array of 271 palindromes and an array of 271 non-palidromes, then tested the array for x Iterations. The score on top is using the Array.Reverse method (the method I posted second) and the bottom score checking character by character (the method I posted first). The score is the average number of ticks per method call. The average non-palindrome was longer than the average palindrome, so that may account for the slightly slower performance.

    Palindromes:

    1000 Iterations
    18.1072177121771
    1000 Iterations
    12.1946568265683

    5000 Iterations
    17.8115896678967
    5000 Iterations
    12.046842804428

    10000 Iterations
    17.2203335793358
    10000 Iterations
    11.4925402214022

    15000 Iterations
    17.121790897909
    15000 Iterations
    11.6280364083641

    20000 Iterations
    17.1833800738007
    20000 Iterations
    11.5294937269373

    30000 Iterations
    17.2080157441574
    30000 Iterations
    11.7019434194342

    Non-Palindromes:

    1000 Iterations
    21.8025682656827
    1000 Iterations
    15.1509372693727

    5000 Iterations
    21.6547542435424
    5000 Iterations
    15.2248442804428

    10000 Iterations
    21.8764752767528
    10000 Iterations
    14.6335881918819

    15000 Iterations
    21.777932595326
    15000 Iterations
    14.6089525215252

    20000 Iterations
    22.0981963099631
    20000 Iterations
    14.6890184501845

    30000 Iterations
    22.3075995079951
    30000 Iterations
    14.7444487084871

    The character by character method beating the Array.Reverse method on non-palindromes is a no brainer, because it returns false after the first check, where as the Array.Reverse has to reverse and test the whole string every time.

    I was a bit surprised by it winning on palindromes, though. If anyone has any insight into this, I'd love to hear it. All I can assume is that a character by character check is more efficient than putting a string into an array, reversing it, and putting it back into a string.

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    public bool IsPalindrome(string palindrome)
    {
       if(palindrome == null || palindrome.Length == 0)
          return false;
       palindrome = palindrome.Replace(" ", "").ToLower();
       char[] reverse = palindrome.ToCharArray();
       Array.Reverse(reverse);
       string s = new string(reverse);
       return palindrome == s;
    }

    Here's a case/space insensitive and smaller palindrome checker.

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    public bool IsPalindrome(string palindrome)
    {
       if(palindrome == null || palindrome.Length == 0)
          return false;

       palindrome = palindrome.Replace(" ", "").ToLower();
       int start = 0, end = palindrome.Length - 1;

       while(end - start >= 1)
       {
          if(palindrome[start] == palindrome[end])
          {
             start++;
             end--;
          }
          else
             return false;
       }

       return true;
    }

    This will validate palindromes without case sensitivity even if they have spaces, for example: A man a plan a canal Panama