Example #1
0
        public void BasicTest()
        {
            String testString = WikipediaTestHelper.GetRandomTestString();
            var    sw         = Stopwatch.StartNew();

            Assert.IsTrue(testString.Length > 0);
            sw.Stop();
            Debug.WriteLine("Time: " + sw.Elapsed.TotalMilliseconds);
        }
Example #2
0
        public void TestAllToCsv()
        {
            FileStream   fs;
            const string fileName = "wikipediaTestValues.csv";

            try
            {
                fs = new FileStream(fileName, FileMode.Truncate);
            }
            catch (FileNotFoundException)
            {
                fs = new FileStream(fileName, FileMode.Create);
            }
            var streamWriter = new StreamWriter(fs);

            streamWriter.WriteLine("length, linq, linqLookup, dictionary, dictionaryNoLinq");
            //generate values for each
            for (int i = 0; i < NumValues; i++)
            {
                var valueToTest = WikipediaTestHelper.GetRandomTestString();
                var length      = valueToTest.Split(' ').Length;
                var sw          = Stopwatch.StartNew();
                var result      = CountWordsInString.CountWordsInString.CountWordsLinq(valueToTest);
                sw.Stop();
                var linqValue = sw.Elapsed.TotalMilliseconds;
                sw.Reset();

                sw     = Stopwatch.StartNew();
                result = CountWordsInString.CountWordsInString.CountWordsDictionary(valueToTest);
                sw.Stop();
                var dictValue = sw.Elapsed.TotalMilliseconds;
                sw.Reset();

                sw     = Stopwatch.StartNew();
                result = CountWordsInString.CountWordsInString.CountWordsDictionaryNoLinq(valueToTest);
                sw.Stop();
                var dictNoLinqValue = sw.Elapsed.TotalMilliseconds;
                sw.Reset();

                sw     = Stopwatch.StartNew();
                result = CountWordsInString.CountWordsInString.CountWordsLinqLookup(valueToTest);
                sw.Stop();
                var dictLinqLookupValue = sw.Elapsed.TotalMilliseconds;
                sw.Reset();



                streamWriter.WriteLine(length + ", " + linqValue + ", " + dictLinqLookupValue + ", " + dictValue + ", " + dictNoLinqValue);
            }
            streamWriter.Close();
            fs.Close();
        }