Last active
          August 29, 2015 14:21 
        
      - 
      
- 
        Save wallstop/390863ffcca6e9143d0c to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using System.Text; | |
| namespace SimpleSortingTest | |
| { | |
| public class SimpleSortTest | |
| { | |
| private static readonly string POSSIBLE_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |
| private static readonly int WORD_LIST_SIZE = 300000; | |
| private static readonly int MAX_WORD_LENGTH = 200; | |
| private static readonly int MIN_WORD_LENGTH = 10; | |
| private static readonly Random RGEN = new Random(); | |
| private static string GenerateArbitraryString() | |
| { | |
| int wordSize = RGEN.Next(MIN_WORD_LENGTH, MAX_WORD_LENGTH); | |
| StringBuilder wordBuilder = new StringBuilder(); | |
| for (int i = 0; i < wordSize; ++i) | |
| { | |
| int index = RGEN.Next(POSSIBLE_CHARACTERS.Length); | |
| wordBuilder.Append(POSSIBLE_CHARACTERS[index]); | |
| } | |
| return wordBuilder.ToString(); | |
| } | |
| private static void Main(string[] args) | |
| { | |
| Stopwatch globalTimer = new Stopwatch(); | |
| Stopwatch sortTimer = new Stopwatch(); | |
| globalTimer.Start(); | |
| List<string> words = new List<string>(WORD_LIST_SIZE); | |
| for (int i = 0; i < WORD_LIST_SIZE; ++i) | |
| { | |
| string word = GenerateArbitraryString(); | |
| words.Add(word); | |
| } | |
| sortTimer.Start(); | |
| words.Sort(); | |
| sortTimer.Stop(); | |
| foreach (string word in words) | |
| { | |
| Console.WriteLine(word); | |
| } | |
| globalTimer.Stop(); | |
| Console.WriteLine( | |
| $"Generation and all output took {globalTimer.ElapsedMilliseconds}ms. Actual sort took {sortTimer.ElapsedMilliseconds}ms"); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment