コード例 #1
0
        public void TestRandomSearchAll()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong counter = 0;

                ulong minLink = 1UL;
                ulong maxLink = links.Total;

                ulong iterations = links.Total;
                var rnd = new Random((int)DateTime.UtcNow.Ticks);

                Console.WriteLine("Testing Random Search with {0} Iterations.", links.Total);

                Stopwatch sw = Stopwatch.StartNew();

                for (ulong i = iterations; i > 0; i--)
                {
                    ulong source = rnd.NextUInt64(minLink, maxLink);
                    ulong target = rnd.NextUInt64(minLink, maxLink);

                    counter += links.Search(source, target);
                }

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = iterations / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} Iterations of Random Search done in {1} ({2} Iterations per second), c: {3}",
                    iterations, elapsedTime, (long)iterationsPerSecond, counter);
            }

            File.Delete(tempFilename);
        }