Ejemplo n.º 1
0
        public void DoubleWhere()
        {
            using (Benchmarker b = new Benchmarker($"ushort[{Count:n0}] | where [Value] < 50 || [Value] > 950 | count", DefaultMeasureMilliseconds))
            {
                b.Measure("For Count", Values.Length, () =>
                {
                    int count = 0;
                    for (int i = 0; i < Values.Length; ++i)
                    {
                        if (Values[i] < 50 || Values[i] > 950)
                        {
                            count++;
                        }
                    }
                    return(count);
                });

                b.Measure("XForm Count", Values.Length, () =>
                {
                    return((int)Context.FromArrays(Values.Length)
                           .WithColumn("Value", Values)
                           .Query("where [Value] < 50 || [Value] > 950", Context)
                           .Count());
                });

                b.AssertResultsEqual();
            }
        }
Ejemplo n.º 2
0
        public void WhereUShortEqualsUshort()
        {
            using (Benchmarker b = new Benchmarker($"ushort[{Count:n0}] | where [Value] = [Threshold] | count", DefaultMeasureMilliseconds))
            {
                b.Measure("For Count", Values.Length, () =>
                {
                    int count = 0;
                    for (int i = 0; i < Values.Length; ++i)
                    {
                        if (Values[i] == Thresholds[i])
                        {
                            count++;
                        }
                    }
                    return(count);
                });

                b.Measure("XForm Count", Values.Length, () =>
                {
                    return((int)Context.FromArrays(Values.Length)
                           .WithColumn("Value", Values)
                           .WithColumn("Threshold", Thresholds)
                           .Query("where [Value] = [Threshold]", Context)
                           .Count());
                });

                b.AssertResultsEqual();
            }
        }
Ejemplo n.º 3
0
        //public void Join()
        //{
        //    int joinFromLength = Math.Min(1000 * 1000, Values.Length);
        //    ushort[] joinTo = Enumerable.Range(10, 1000).Select((i) => (ushort)i).ToArray();

        //    using (Benchmarker b = new Benchmarker($"ushort[{joinFromLength:n0}] | join [Value] | count", DefaultMeasureMilliseconds))
        //    {
        //        b.Measure("XForm Join", joinFromLength, () =>
        //        {
        //            IXTable joinToSource = Context.FromArrays(joinTo.Length).WithColumn("ID", joinTo);

        //            IXTable enumerator = Context.FromArrays(joinFromLength).WithColumn("Value", Values);
        //            enumerator = new Join(enumerator, "Value", joinToSource, "ID", "");
        //            return (int)enumerator.Count();
        //        });
        //    }
        //}

        public void Dictionary()
        {
            int count = 4 * 1000 * 1000;
            Dictionary <int, int>  expected = new Dictionary <int, int>();
            Dictionary5 <int, int> actual   = new Dictionary5 <int, int>(new EqualityComparerAdapter <int>(TypeProviderFactory.Get(typeof(int)).TryGetComparer()));

            int[]  values = new int[count];
            Random r      = new Random(5);

            for (int i = 0; i < count; ++i)
            {
                values[i] = r.Next();
            }

            using (Benchmarker b = new Benchmarker($"Dictionary<int, int> [{count:n0}]", DefaultMeasureMilliseconds))
            {
                b.Measure("System.Collections.Generic.Dictionary", count, () =>
                {
                    int containsCount = 0;
                    for (int i = 0; i < count; ++i)
                    {
                        expected[values[i]] = i;
                        if (expected.ContainsKey(values[i]))
                        {
                            containsCount++;
                        }
                    }

                    return(expected.Count + containsCount);
                });

                b.Measure("XForm.Dictionary5", count, () =>
                {
                    int containsCount = 0;
                    for (int i = 0; i < count; ++i)
                    {
                        actual.Add(values[i], i);
                        if (actual.ContainsKey(values[i]))
                        {
                            containsCount++;
                        }
                    }

                    return(actual.Count + containsCount);
                });

                b.AssertResultsEqual();
            }
        }
Ejemplo n.º 4
0
        public void ByteEqualsConstant()
        {
            byte[] bytes = new byte[1000 * 1000];
            Random r     = new Random(8);

            r.NextBytes(bytes);

            using (Benchmarker b = new Benchmarker($"byte[{bytes.Length:n0}] | where [Value] < 16 | count", DefaultMeasureMilliseconds))
            {
                b.Measure("For Count", bytes.Length, () =>
                {
                    int count = 0;
                    for (int i = 0; i < bytes.Length; ++i)
                    {
                        if (bytes[i] < 16)
                        {
                            count++;
                        }
                    }
                    return(count);
                });

                b.Measure("Linq Count", bytes.Length, () =>
                {
                    return(bytes.Where((i) => i < 16).Count());
                });

                b.Measure("XForm Count", bytes.Length, () =>
                {
                    return((int)Context.FromArrays(bytes.Length)
                           .WithColumn("Value", bytes)
                           .Query("where [Value] < 16", Context)
                           .Count());
                });

                b.AssertResultsEqual();
            }
        }