Exemplo n.º 1
0
        public void CouldLagSeries() {
            var sm = new SortedMap<double, double>();

            var count = 1000000;

            for (int i = 0; i < count; i++) {
                sm.Add(i, i);
            }

            // slow implementation
            var sw = new Stopwatch();
            sw.Start();
            var lag = sm.Lag(1);//.ToSortedMap();
            var c = 1;
            foreach (var zl in lag) {
                if (c - 1 != zl.Value) {
                    throw new ApplicationException();
                }
                c++;
            }
            sw.Stop();
            Console.WriteLine($"Final c: {c}");
            Console.WriteLine("ZipLag, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));

            var repeated = lag.Repeat();

            for (int i = 1; i < 1000; i++)
            {
                double v;
                Assert.IsTrue(repeated.TryGetValue(i+1.5, out v));
                Assert.AreEqual(i, v);
            }

        }
Exemplo n.º 2
0
        public void CouldLagSeries()
        {
            var sm = new SortedMap <double, double>();

            var count = 1000000;

            for (int i = 0; i < count; i++)
            {
                try
                {
                    sm.Add(i, i);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"i: {i}");
                    Console.WriteLine($"sm.count: {sm.Count}");
                    Console.WriteLine($"sm.IsRegular: {sm.IsRegular}");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    throw e;
                }
            }

            // slow implementation
            var sw = new Stopwatch();

            sw.Start();
            var lag = sm.Lag(1);//.ToSortedMap();
            var c   = 1;

            foreach (var zl in lag)
            {
                if (c - 1 != zl.Value)
                {
                    throw new ApplicationException();
                }
                c++;
            }
            sw.Stop();
            Console.WriteLine($"Final c: {c}");
            Console.WriteLine("ZipLag, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));

            var repeated = lag.Repeat();

            for (int i = 1; i < 1000; i++)
            {
                double v;
                Assert.IsTrue(repeated.TryFind(i + 1.5, Lookup.EQ, out var kvp));
                Assert.AreEqual(i, kvp.Value);
            }
        }
Exemplo n.º 3
0
        public void CouldLagSeries()
        {
            var sm = new SortedMap <double, double>();

            var count = 1000000;

            for (int i = 0; i < count; i++)
            {
                sm.Add(i, i);
            }

            // slow implementation
            var sw = new Stopwatch();

            sw.Start();
            var lag = sm.Lag(1);//.ToSortedMap();
            var c   = 1;

            foreach (var zl in lag)
            {
                if (c - 1 != zl.Value)
                {
                    throw new ApplicationException();
                }
                c++;
            }
            sw.Stop();
            Console.WriteLine($"Final c: {c}");
            Console.WriteLine("ZipLag, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));

            var repeated = lag.Repeat();

            for (int i = 1; i < 1000; i++)
            {
                double v;
                Assert.IsTrue(repeated.TryGetValue(i + 1.5, out v));
                Assert.AreEqual(i, v);
            }
        }