public void TestGetTarget() { string tempFilename = Path.GetTempFileName(); using (var links = new Links(tempFilename, DefaultLinksSize)) { Console.WriteLine("Testing GetTarget function with {0} Iterations.", Iterations); ulong counter = 0; //var firstLink = links.First(); ulong firstLink = links.Create(0, 0); Stopwatch sw = Stopwatch.StartNew(); for (ulong i = 0; i < Iterations; i++) counter += links.GetTarget(firstLink); TimeSpan elapsedTime = sw.Elapsed; double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds; links.Delete(firstLink); Console.WriteLine( "{0} Iterations of GetTarget function done in {1} ({2} Iterations per second), counter result: {3}", Iterations, elapsedTime, (long)iterationsPerSecond, counter); } File.Delete(tempFilename); }
public void TestGetTargetInParallel() { string tempFilename = Path.GetTempFileName(); using (var links = new Links(tempFilename, DefaultLinksSize)) { Console.WriteLine("Testing GetTarget function with {0} Iterations in parallel.", Iterations); long counter = 0; //var firstLink = links.First(); ulong firstLink = links.Create(0, 0); Stopwatch sw = Stopwatch.StartNew(); Parallel.For(0, Iterations, x => { Interlocked.Add(ref counter, (long)links.GetTarget(firstLink)); //Interlocked.Increment(ref counter); }); TimeSpan elapsedTime = sw.Elapsed; double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds; links.Delete(firstLink); Console.WriteLine( "{0} Iterations of GetTarget function done in {1} ({2} Iterations per second), counter result: {3}", Iterations, elapsedTime, (long)iterationsPerSecond, counter); } File.Delete(tempFilename); }
private static void PrintContents(Links links, Sequences sequences) { if (links.Total == UTF16LastCharLink) Console.WriteLine("Database is empty."); else { Console.WriteLine("Contents:"); var linksTotalLength = links.Total.ToString("0").Length; var printFormatBase = new String('0', linksTotalLength); // Выделить код по печати одной связи в Extensions var printFormat = string.Format("\t[{{0:{0}}}]: {{1:{0}}} -> {{2:{0}}} {{3}}", printFormatBase); for (var link = UTF16LastCharLink + 1; link <= links.Total; link++) { Console.WriteLine(printFormat, link, links.GetSource(link), links.GetTarget(link), sequences.FormatSequence(link, AppendLinkToString, true)); } } }