Esempio n. 1
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));
    }
Esempio n. 2
0
 public void NoValues()
 {
   var sut = new SimpleValuesHolder();
   int expected = sut.ExpectedFromCodegen();
   
   Assert.AreEqual(expected, sut.GetHash(compiler));
   Assert.AreEqual(10, debugStats.statsPrimitive, "fields compiled");
   Assert.AreEqual(0, debugStats.StatsEnum);
   Assert.AreEqual(0, debugStats.StatsIcollection);
 }
Esempio n. 3
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));
    }
Esempio n. 4
0
 public void AreWeGeneratingAsStandardGetHashcode()
 {
   var sut = new SimpleValuesHolder();
   this.StandardTesting(sut);
 }
Esempio n. 5
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));

    }
Esempio n. 6
0
    void AssignValues(SimpleValuesHolder sut)
    {
      sut.c = 'c';
      sut.i = 42433;
      sut.ui = 2983983;
      sut.b = true;
      sut.l = -23832232;
      sut.ul = 399992;
      sut.by = 3;

    }
Esempio n. 7
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);
    }