AlgoLib.Tests.TrieTestsBenchmark.BenchmarkTest C# (CSharp) Метод

BenchmarkTest() приватный Метод

private BenchmarkTest ( ) : void
Результат void
        public void BenchmarkTest()
        {
            const int Count = 1;

            var words = GetWords();

            TestContext.WriteLine(
                "Words count: {0}. Iterations count: {1}. Prefixes count: {2}.", words.Count(), Count, Prefixes.Length);

            var stopWatch = Stopwatch.StartNew();

            for (int i = 0; i < Count; i++)
            {
                foreach (var prefix in Prefixes)
                {
                    var resultArray = words.Where(w => w.StartsWith(prefix)).ToArray();
                }
            }

            stopWatch.Stop();

            TestContext.WriteLine("ToArray method: {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();

            var trie = new Trie<bool>();
            trie.AddRange(words.Select(w => new TrieEntry<bool>(w, false)));

            stopWatch.Stop();

            TestContext.WriteLine("Build tree: {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();

            for (int i = 0; i < Count; i++)
            {
                foreach (var prefix in Prefixes)
                {
                    var resultTrie = trie.GetByPrefix(prefix).Select(w => w.Key).ToArray();
                }
            }

            stopWatch.Stop();

            TestContext.WriteLine("Trie find prefixes: {0}", stopWatch.ElapsedMilliseconds);
        }