示例#1
0
        public void CouldWriteToStorage()
        {
            var repo = new SeriesStorage(SeriesStorage.GetDefaultConnectionString("../StorageTests.db"));
            var test = new SortedMap <DateTime, double>();

            for (int i = 0; i < 10; i++)
            {
                test.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
            }
            test.Complete();
            foreach (var kvp in test.Map(x => (decimal)x))
            {
                Console.WriteLine($"{kvp.Key} - {kvp.Key.Kind} - {kvp.Value}");
            }

            var storageSeries = repo.GetPersistentOrderedMap <DateTime, decimal>("test_series_CouldWriteToStorage");
            var test2         = storageSeries.ToSortedMap();

            foreach (var kvp in test2)
            {
                Console.WriteLine($"{kvp.Key} - {kvp.Key.Kind} - {kvp.Value}");
            }
            storageSeries.Append(test.Map(x => (decimal)x), AppendOption.RequireEqualOverlap);
            storageSeries.Flush();
        }
示例#2
0
        public void CouldConsumeMapAsync()
        {
            var count  = 10;
            var sm     = new SortedMap <int, int>();
            var zipMap = sm.Map(x => x * x).Zip(sm.Map(x => x * x), (l, r) => l + r);

            var t1 = Task.Run(async() =>
            {
                for (int i = 0; i < count; i++)
                {
                    await Task.Delay(250);
                    var _ = await sm.TryAdd(i, i);
                }
                await sm.Complete();
            });
            var cnt = 0;
            var t2  = Task.Run(async() =>
            {
                var c = zipMap.GetAsyncCursor();

                while (await c.MoveNextAsync())
                {
                    cnt++;
                    Console.WriteLine($"{c.CurrentKey} - {c.CurrentValue}");
                }
            });

            Task.WhenAll(t1, t2).Wait();
            Assert.AreEqual(count, cnt);
        }
示例#3
0
        public void CouldCancelMapCursor()
        {
            var sm = new SortedMap <int, int>();

            sm.Add(1, 1);

            var range = sm.Map(x => x + 1).Range(0, Int32.MaxValue, true, true);

            var cursor = range.GetCursor();

            Assert.True(cursor.MoveNext());
            Assert.False(cursor.MoveNext());

            var cts = new CancellationTokenSource();

            var t = Task.Run(() =>
            {
                Thread.Sleep(100);
                var task = cursor.MoveNext(cts.Token);
                Assert.True(task.IsCanceled);
                //task.Wait();
            });

            cts.Cancel();
            t.Wait();
        }
示例#4
0
        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.Range(new Opt <int>(0), Opt <int> .Missing, true, true);
                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)}");
            //}
        }
示例#5
0
        public void CouldMapValuesViaExtensionMethods()
        {
            var sm = new SortedMap <int, int>
            {
                { 1, 1 }
            };

            var map    = sm.Map(i => i * 2);
            var map11  = map.Map(i => i * 2);
            var map111 = map11.Map(i => i * 2);
            var map2   = map.Range(0, Int32.MaxValue, true, true).Map(i => i * 2).Map(i => i * 2);

            Assert.AreEqual(2, map.First.Value);
            Assert.AreEqual(2 * 2, map11.First.Value);
            Assert.AreEqual(2 * 2 * 2, map111.First.Value);
            Assert.AreEqual(8, map2.First.Value);
        }
示例#6
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)}");
            }
        }