private void Run <T>(AutoStopwatch parent, Func <Random, T> getRandomValue) where T : struct, IComparable <T>
        {
            for (int exp = MIN_EXP; exp <= MAX_EXP; exp += EXP_STEP)
            {
                using (var child = parent.CreateChild(prefix: $"{typeof(T).Name} ", postfix: $" (2^{exp})"))
                {
                    T[] randomData1, randomData2;
                    using (var awCompare = child.CreateChild(stepName: "Create Data"))
                    {
                        randomData1 = new T[1 << exp];
                        randomData2 = new T[1 << exp];
                        var random = new Random();
                        for (int i = 0; i < randomData1.Length; i++)
                        {
                            randomData1[i] = getRandomValue(random);
                            randomData2[i] = getRandomValue(random);
                        }
                    }

                    var v = this.RunGenericVectorized(child, randomData1, randomData2);
                    var c = this.RunGenericConventional(child, randomData1, randomData2);

                    using (var awCompare = child.CreateChild(stepName: "Compare Results"))
                    {
                        ArrayComparer.Compare(v.add, c.add);
                        ArrayComparer.Compare(v.sub, c.sub);
                        ArrayComparer.Compare(v.mul, c.mul);
                        ArrayComparer.Compare(v.div, c.div);
                    }
                }
            }
        }
Beispiel #2
0
        public void IntegerComparer_NotReversed_ExpectResultLessThanZero()
        {
            var comparer = new ArrayComparer <int>(false);

            comparer.SetItems(new int[] { 0, 1 });

            var result = comparer.Compare(0, 1);

            Assert.True(result < 0);
        }
Beispiel #3
0
        public void IntegerComparer_ComparingEqualValues_ExpectResultEqualToZero()
        {
            var comparer = new ArrayComparer <int>(false);

            comparer.SetItems(new int[] { 2, 2 });

            var result = comparer.Compare(0, 1);

            Assert.True(result == 0);
        }
Beispiel #4
0
        public void IntegerComparer_Reversed_ExpectResultGreaterThanZero()
        {
            var comparer = new ArrayComparer <int>(true);

            comparer.SetItems(new int[] { 0, 1 });

            var result = comparer.Compare(0, 1);

            Assert.True(result > 0);
        }