Ejemplo n.º 1
0
        public void BoolValue()
        {
            var sut = new SimpleValuesHolder();

            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));

            sut.b = true;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
        }
Ejemplo n.º 2
0
        //[Test]
        //public void AreWeGeneratingAsStandardGetHashcodeWithStd()
        //{
        //  compiler.should_inline_hash_for_primitives = false; // use .GetHashCode() on all input
        //  var sut = new SimpleValuesHolder(compiler);
        //  StandardTesting(sut);
        //}

        void StandardTesting(SimpleValuesHolder sut)
        {
            // TODO test alle felterne

            sut.c = 'c';
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            Assert.AreEqual(10, debugStats.statsPrimitive, "fields compiled");


            sut.i = 42433;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.ui = 2983983;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.b = true;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.l = -23832232;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.ul = 399992;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.by = 3;
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));
            Console.WriteLine(sut.GetHash(compiler));
        }
Ejemplo n.º 3
0
        public void Value()
        {
            var sut = new SimpleValuesHolder();

            sut.c = 'c';
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            Assert.AreEqual(10, debugStats.statsPrimitive, "fields compiled");


            sut.i = 42433;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.ui = 2983983;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.b = true;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.l = -23832232;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.ul = 399992;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));

            sut.by = 3;
            Assert.AreEqual(sut.ExpectedFromCodegen(), sut.GetHash(compiler));
            Assert.AreEqual(sut.StandardHashCode(), sut.GetHash(compiler));
        }
Ejemplo n.º 4
0
        public void ValuesTiming()
        {
            Compiler.Logging = false;

            var N   = 1000000;
            var sut = new SimpleValuesHolder();

            AssignValues(sut);

            // pre-compile before timing
            var mth = compiler.CreateHashingMethod <SimpleValuesHolder>();

            mth(sut);


            var time = Timer.TimeInMillis(() =>
            {
                for (int i = 0; i < N; i++)
                {
                    x = mth(sut);
                }
            });

            Console.WriteLine("call gethashcode()");
            Console.WriteLine(time + "    " + x);

            time = Timer.TimeInMillis(() =>
            {
                for (int i = 0; i < N; i++)
                {
                    x = sut.StandardHashCode();
                }
            });
            Console.WriteLine("std");
            Console.WriteLine(time + "    " + x);


            //  compiler = new Compiler(new Dictionary<Type, HashingMethod>());
            //  compiler.should_inline_hash_for_primitives = true;
            //  sut = new SimpleValuesHolder(compiler);
            //  // pre-compile before run
            //sut.GetHash(compiler);

            //time = Timer.TimeInMillis(() =>
            //                                {
            //                                  for (int i = 0; i < N; i++)

            //                                  {
            //                                    x = sut.GetHash(compiler);
            //                                  }
            //                                });
            //Console.WriteLine("inline calls");
            //Console.WriteLine(time + "    " + x);
        }