public void GetSourceTest() { string tempFilename = Path.GetTempFileName(); using (var links = new Platform.Links.DataBase.CoreUnsafe.Pairs.Links(tempFilename, DefaultLinksSize)) { Console.WriteLine("Testing GetSource 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.GetSource(firstLink); TimeSpan elapsedTime = sw.Elapsed; double iterationsPerSecond = Iterations/elapsedTime.TotalSeconds; // Удаляем связь, из которой производилось считывание links.Delete(ref firstLink); Console.WriteLine( "{0} Iterations of GetSource function done in {1} ({2} Iterations per second), counter result: {3}", Iterations, elapsedTime, (long) iterationsPerSecond, counter); } File.Delete(tempFilename); }
public void GetSourceInParallel() { string tempFilename = Path.GetTempFileName(); using (var links = new Platform.Links.DataBase.CoreUnsafe.Pairs.Links(tempFilename, DefaultLinksSize)) { Console.WriteLine("Testing GetSource 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.GetSource(firstLink)); //Interlocked.Increment(ref counter); }); TimeSpan elapsedTime = sw.Elapsed; double iterationsPerSecond = Iterations/elapsedTime.TotalSeconds; links.Delete(ref firstLink); Console.WriteLine( "{0} Iterations of GetSource function done in {1} ({2} Iterations per second), counter result: {3}", Iterations, elapsedTime, (long) iterationsPerSecond, counter); } File.Delete(tempFilename); }