public void CouldMapValues() { var sm = new SortedMap <int, double> { { 1, 1 } }; Series <int, double, Range <int, double, SortedMapCursor <int, double> > > s1; s1 = sm.After(1); // TODO see the monster signature! // try to swap Map with Range (or any CursorSeries) so that this signature could // be automatically reduced to just two step var m2 = s1.Map((x) => x + 1).After(1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1); var map = new MapValuesSeries <int, double, double, SortedMapCursor <int, double> >(sm.GetEnumerator(), i => i * 2); var map1 = new MapValuesSeries <int, double, double, MapValuesSeries <int, double, double, SortedMapCursor <int, double> > >(map, i => i * 2); var map2 = new MapValuesSeries <int, double, double, Cursor <int, double> >(new Cursor <int, double>(map.Range(0, Int32.MaxValue, true, true).GetEnumerator()), i => i * 2); var map3 = new MapValuesSeries <int, double, double, Cursor <int, double> >(new Cursor <int, double>(map.Range(2, Int32.MaxValue, true, true).GetEnumerator()), i => i * 2); Assert.AreEqual(2, map.First.Value); Assert.AreEqual(4, map1.First.Value); Assert.AreEqual(4, map2.First.Value); Assert.True(map3.IsEmpty); }
public void CouldMapRangeSeriesViaExtensionMethodsBenchmark() { 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 range = sm.After(0); var map = sm.Map(i => i * 2); //var range2 = map.Range(0, int.MaxValue, true, true); //var map2 = range2.Map(i => i * 2); //var range3 = map2.Range(0, int.MaxValue, true, true); //var map3 = range3.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)); // long sum = 0; // foreach (var kvp in map) // { // sum += kvp.Value; // } // sw.Stop(); // Assert.IsTrue(sum > 0); // Console.WriteLine($"LINQ Mops {sw.MOPS(count)}"); //} }
/// <summary> /// Sample for the map combination. This tests mostly intellisense experience - see popup on m2 /// with and without the two methods above /// </summary> // ReSharper disable once UnusedMember.Local private static void TestMovingRangeBeforeMap() { var sm = new SortedMap <int, double> { { 1, 1 } }; Series <int, double, Range <int, double, SortedMapCursor <int, double> > > s1; s1 = sm.After(1); // ReSharper disable once UnusedVariable var m2 = (s1.Map((x) => x + 1)).After(1).After(1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) .Map((x) => x + 1).After(1).Map((x) => x + 1).After(1).Map((x) => x + 1) ; }