Пример #1
0
        public static Stat2 <TKey> Stat2 <TKey, TValue, TCursor>(
            this Series <TKey, TValue, TCursor> series)
            where TCursor : ICursor <TKey, TValue, TCursor>
        {
            var stat = new Stat2 <TKey>();

            using (var cursor = series.GetEnumerator())
            {
                var first = true;
                while (cursor.MoveNext())
                {
                    if (first)
                    {
                        stat._start = cursor.CurrentKey;
                        first       = false;
                    }
                    stat.AddValue(DoubleUtil.GetDouble(cursor.CurrentValue));
                }

                stat._end      = cursor.CurrentKey;
                stat._endValue = DoubleUtil.GetDouble(cursor.CurrentValue);
            }

            return(stat);
        }
Пример #2
0
        public Stat2 <TKey> GetResult(ref TCursor left, ref TCursor right)
        {
            var copy = _state;

            copy._start    = left.CurrentKey;
            copy._end      = right.CurrentKey;
            copy._endValue = DoubleUtil.GetDouble(right.CurrentValue);
            return(copy);
        }
Пример #3
0
        public static Stat2 <TKey> Stat2 <TKey, TValue>(this ISeries <TKey, TValue> series)
        {
            var stat = new Stat2 <TKey>();

            using (var cursor = series.GetSpecializedCursor())
            {
                var first = true;
                while (cursor.MoveNext())
                {
                    if (first)
                    {
                        stat._start = cursor.CurrentKey;
                        first       = false;
                    }
                    stat.AddValue(DoubleUtil.GetDouble(cursor.CurrentValue));
                }

                stat._end      = cursor.CurrentKey;
                stat._endValue = DoubleUtil.GetDouble(cursor.CurrentValue);
            }

            return(stat);
        }
Пример #4
0
        public void RemoveOldLeft(KeyValuePair <TKey, TValue> oldLeft)
        {
            var x = DoubleUtil.GetDouble(oldLeft.Value);

            _state.RemoveValue(x);
        }
Пример #5
0
        public void AddNewLeft(KeyValuePair <TKey, TValue> newLeft)
        {
            var x = DoubleUtil.GetDouble(newLeft.Value);

            _state.AddValue(x);
        }
Пример #6
0
        public void CouldConvertToDoubleDynamic()
        {
            var count = 10_000_000;

            for (int r = 0; r < 20; r++)
            {
                var sum = 0.0;
                using (Benchmark.Run("Dynamic cast", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dyn   = (dynamic)price;
                        var dbl   = (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Convert nobox", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dbl   = Convert.ToDouble(price);
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Convert box", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dbl   = Convert.ToDouble((object)price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("DoubleUtil nobox", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dbl   = DoubleUtil.GetDouble(price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("DoubleUtil box", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dbl   = DoubleUtil.GetDouble((object)price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Direct", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = new Price((double)i);
                        var dbl   = price.AsDouble;
                        sum += dbl;
                    }
                }

                Assert.IsTrue(sum > 0);
            }
            Benchmark.Dump();
        }
Пример #7
0
        public void CouldConvertToDoubleDynamic()
        {
#if DEBUG
            var count = 10_000;
#else
            var count = 10_000_000;
#endif
            for (int r = 0; r < 20; r++)
            {
                var sum = 0.0;
                using (Benchmark.Run("Dynamic cast", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dyn   = (dynamic)price;
                        // ReSharper disable once PossibleInvalidCastException
                        var dbl = (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Convert nobox", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dbl   = Convert.ToDouble(price);
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Convert box", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dbl   = Convert.ToDouble((object)price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("DoubleUtil nobox", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dbl   = DoubleUtil.GetDouble(price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("DoubleUtil box", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dbl   = DoubleUtil.GetDouble((object)price); // (double)dyn;
                        sum += dbl;
                    }
                }

                using (Benchmark.Run("Direct", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var price = (SmallDecimal)((double)i);
                        var dbl   = (double)price;
                        sum += dbl;
                    }
                }

                Assert.IsTrue(sum > 0);
            }
            Benchmark.Dump();
        }