public void CouldMapValuesBenchmark() { var sm = new SortedMap <int, double>(); var count = 10000000; //sm.AddLast(0, 0); // make irregular for (int i = 2; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { var map = new ArithmeticSeries <int, double, MultiplyOp <double>, SortedMapCursor <int, double> >( sm.GetEnumerator(), 2.0); var map2 = new ArithmeticSeries <int, double, MultiplyOp <double>, ArithmeticSeries <int, double, MultiplyOp <double>, SortedMapCursor <int, double> > >( map, 2.0); var sum = 0.0; using (Benchmark.Run("ArithmeticSeries", count)) { foreach (var kvp in map2) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } for (int r = 0; r < 10; r++) { var map = sm //.Select(x => new KeyValuePair<int, double>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)); var sum = 0.0; using (Benchmark.Run("LINQ", count)) { foreach (var kvp in map) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } }
public void CouldMapValuesViaExtensionMethodsBenchmark() { var sm = new SortedMap <int, int>(); var count = 10000000; for (int i = 0; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { var sw = new Stopwatch(); sw.Restart(); var map = sm.Map(i => i * 2).Range(0, int.MaxValue, true, true).Map(i => i * 2).Map(i => i * 2); long sum = 0; foreach (var kvp in map) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"Mops {sw.MOPS(count)}"); } for (int r = 0; r < 10; r++) { var sw = new Stopwatch(); sw.Restart(); var map = sm .Select(x => new KeyValuePair <int, int>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, int>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, int>(x.Key, x.Value * 2)); long sum = 0; foreach (var kvp in map) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"LINQ Mops {sw.MOPS(count)}"); } }
public void CouldMapValuesBenchmark() { var sm = new SortedMap <int, int>(); var count = 10000000; for (int i = 0; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { var sw = new Stopwatch(); sw.Restart(); var map = new MapValuesSeries <int, int, int, SortedMapCursor <int, int> >(sm, i => i * 2); long sum = 0; foreach (var kvp in map) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"Mops {sw.MOPS(count)}"); } for (int r = 0; r < 10; r++) { var sw = new Stopwatch(); sw.Restart(); var map = sm.Select(x => new KeyValuePair <int, int>(x.Key, x.Value * 2)); long sum = 0; foreach (var kvp in map) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"LINQ Mops {sw.MOPS(count)}"); } }
public void CouldMapValuesWithOperatorBenchmark() { var sm = new SortedMap <int, double>(); var count = 10000000; sm.AddLast(0, 0); for (int i = 2; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { var map = sm * 2; var map2 = map * 2; var sum = 0.0; using (Benchmark.Run("BaseSeries", count)) { foreach (var kvp in map2) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } for (int r = 0; r < 10; r++) { var map = sm .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)); var sum = 0.0; using (Benchmark.Run("LINQ", count)) { foreach (var kvp in map) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } }
public void CouldMapValuesBenchmarkArithmeticVsMapCursor() { var sm = new SortedMap <int, double>(); var count = 10000000; sm.AddLast(0, 0); for (int i = 2; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { var sw = new Stopwatch(); { sw.Restart(); var sum = 0.0; foreach (var kvp in sm) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"SortedMap {sw.MOPS(count)}"); } { sw.Restart(); var map = new ArithmeticSeries <int, double, MultiplyOp <double>, SortedMapCursor <int, double> >(sm, 2.0); var map2 = new ArithmeticSeries <int, double, MultiplyOp <double>, ArithmeticSeries <int, double, MultiplyOp <double>, SortedMapCursor <int, double> > >( map, 2.0); var sum = 0.0; foreach (var kvp in map2) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"ArithmeticSeries {sw.MOPS(count)}"); } { sw.Restart(); var map = new MapValuesSeries <int, double, double, SortedMapCursor <int, double> >(sm, i => Apply(i, 2.0)); var map2 = new MapValuesSeries <int, double, double, MapValuesSeries <int, double, double, SortedMapCursor <int, double> > >(map, i => Apply(i, 2.0)); var sum = 0.0; foreach (var kvp in map2) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"MapValuesSeries {sw.MOPS(count)}"); } { sw.Restart(); var map = sm .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)); var sum = 0.0; foreach (var kvp in map) { sum += kvp.Value; } sw.Stop(); Assert.IsTrue(sum > 0); Console.WriteLine($"LINQ {sw.MOPS(count)}"); } } }
public void CouldMapValuesBenchmarkArithmeticVsMapCursor() { var sm = new SortedMap <int, double>(); var count = 10000000; sm.AddLast(0, 0); for (int i = 2; i < count; i++) { sm.AddLast(i, i); } for (int r = 0; r < 10; r++) { { var sum = 0.0; using (Benchmark.Run("SortedMap", count)) { foreach (var kvp in sm) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } { var map = new ArithmeticSeries <int, double, MultiplyOp <double>, SortedMapCursor <int, double> >(sm.GetEnumerator(), 2.0); var map2 = map + 2; //new ArithmeticSeries<int, double, MultiplyOp<double>, ArithmeticSeries<int, double, // MultiplyOp<double>, SortedMapCursor<int, double>>>( // map.Initialize, 2.0); var sum = 0.0; using (Benchmark.Run("ArithmeticSeries", count)) { foreach (var kvp in map2) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } { var c = new Op <int, double, MultiplyOp <double>, SortedMapCursor <int, double> >( sm.GetEnumerator(), 2.0); var c1 = new Op <int, double, AddOp <double>, Op <int, double, MultiplyOp <double>, SortedMapCursor <int, double> > >( c, 2.0); var series = new Series <int, double, Op <int, double, AddOp <double>, Op <int, double, MultiplyOp <double>, SortedMapCursor <int, double> > > >(c1); var sum = 0.0; using (Benchmark.Run("ArithmeticCursor", count)) { foreach (var kvp in series) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } { var map = new MapValuesSeries <int, double, double, SortedMapCursor <int, double> >(sm.GetEnumerator(), i => Apply(i, 2.0)); var map2 = new MapValuesSeries <int, double, double, MapValuesSeries <int, double, double, SortedMapCursor <int, double> > >(map, i => Apply2(i, 2.0)); var sum = 0.0; using (Benchmark.Run("MapValuesSeries", count)) { foreach (var kvp in map2) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } { var map = (sm * 2) + 2; var sum = 0.0; using (Benchmark.Run("BaseSeries operator", count)) { foreach (var kvp in map) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } { var map = sm .Select(x => new KeyValuePair <int, double>(x.Key, x.Value * 2)) .Select(x => new KeyValuePair <int, double>(x.Key, x.Value + 2)); var sum = 0.0; using (Benchmark.Run("LINQ", count)) { foreach (var kvp in map) { sum += kvp.Value; } } Assert.IsTrue(sum > 0); } } Benchmark.Dump(); }