Exemple #1
0
        // Increment the value of x with the value d
        public void increment(ulong key, IIncrementable <T> v)
        {
            ulong    hash = h(key);
            Node <T> head = nodeList[hash];

            if (head == null)
            {
                nodeList[hash] = new Node <T>(key, v);
                count++;
                return;
            }

            while (head.Key != key && head.Next != null)
            {
                head = head.Next;
            }

            if (head.Key == key)
            {
                head.Data.Increment(v.GetValue());
            }
            else
            {
                head.Next = new Node <T>(key, v);
                count++;
            }
        }
Exemple #2
0
        public void InterceptNonVirtualMethodThatBelongsToAnInterface()
        {
            NopInterceptor ni = new NopInterceptor();

            AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());

            advised.AddAdvice(ni);

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            Assert.AreEqual(0, proxiedClass.Value);
            Assert.AreEqual(0, ni.Count);

            Assert.IsTrue(proxy is IIncrementable);
            IIncrementable proxiedInterface = proxy as IIncrementable;

            proxiedInterface.Increment();
            Assert.AreEqual(1, proxiedInterface.Value);
            Assert.AreEqual(2, ni.Count);
        }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        finished = false;

        eventEmitter = GameObject
                       .FindObjectOfType <EventEmitterContainer> ()
                       .GetEventEmitter();

        progressable = GameObject
                       .FindObjectOfType <ProgressBar.ProgressBarBehaviour> ();
    }
Exemple #4
0
 private static void CallVsCallVirt_Class_IFace(int count)
 {
     using (Benchmark.Run("Class>IFace", count))
     {
         IIncrementable cli = (IIncrementable) new ThisIsClass();
         for (int i = 0; i < count; i++)
         {
             cli.Increment();
         }
     }
 }
Exemple #5
0
 private static void CallVsCallVirt_Struct_IFace(int count)
 {
     using (Benchmark.Run("Str>Interface", count))
     {
         IIncrementable strAsInterface = (IIncrementable)(new ThisIsSrtuct(new byte[4]));
         for (int i = 0; i < count; i++)
         {
             strAsInterface.Increment();
         }
     }
 }
Exemple #6
0
        public void DirectCall()
        {
            AdvisedSupport advised = new AdvisedSupport();

            advised.Target = new InheritanceTestObject();

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            proxiedClass.Name = "DirectCall";
            Assert.AreEqual("DirectCall", proxiedClass.Name);

            Assert.IsTrue(proxy is IIncrementable);
            IIncrementable proxiedIntf = proxy as IIncrementable;

            proxiedIntf.Increment();
            Assert.AreEqual(1, proxiedIntf.Value);
        }
Exemple #7
0
        public void CallVsCallVirt(int r)
        {
            var count = 100000000;
            var sw    = new Stopwatch();

            sw.Restart();
            int *ptr = stackalloc int[1];

            int intValue = 0;

            for (int i = 0; i < count; i++)
            {
                *((int *)ptr) = *((int *)ptr) + 1;
                intValue      = (*((int *)ptr));
            }
            sw.Stop();
            Console.WriteLine($"Value {sw.ElapsedMilliseconds} ({intValue})");

            sw.Restart();
            var str = new ThisIsSrtuct(new byte[4]);

            for (int i = 0; i < count; i++)
            {
                str.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Struct {sw.ElapsedMilliseconds}");

            sw.Restart();
            IIncrementable strAsInterface = (IIncrementable)(new ThisIsSrtuct(new byte[4]));

            for (int i = 0; i < count; i++)
            {
                strAsInterface.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Struct as Interface {sw.ElapsedMilliseconds}");

            var constrainedStr = (new ThisIsSrtuct(new byte[4]));

            ConstrainedStruct(constrainedStr);

            sw.Restart();
            for (int i = 0; i < count; i++)
            {
                ThisIsStaticClass.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Static Class {sw.ElapsedMilliseconds}");

            sw.Restart();
            var cl = new ThisIsClass();

            for (int i = 0; i < count; i++)
            {
                cl.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Class {sw.ElapsedMilliseconds}");

            sw.Restart();
            var scl = new ThisIsSealedClass();

            for (int i = 0; i < count; i++)
            {
                scl.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Sealed Class {sw.ElapsedMilliseconds}");

            sw.Restart();
            IIncrementable cli = (IIncrementable) new ThisIsClass();

            for (int i = 0; i < count; i++)
            {
                cli.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Class as Interface {sw.ElapsedMilliseconds}");

            sw.Restart();
            var dcl = new ThisIsDerivedClass();

            for (int i = 0; i < count; i++)
            {
                dcl.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Derived Class {sw.ElapsedMilliseconds}");

            sw.Restart();
            IIncrementable dcli = (IIncrementable) new ThisIsDerivedClass();

            for (int i = 0; i < count; i++)
            {
                dcli.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Derived Class as Interface {sw.ElapsedMilliseconds}");

            sw.Restart();
            var sdcl = new ThisIsSealedDerivedClass();

            for (int i = 0; i < count; i++)
            {
                sdcl.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Sealed Derived Class {sw.ElapsedMilliseconds}");

            sw.Restart();
            IIncrementable sdcli = (IIncrementable) new ThisIsSealedDerivedClass();

            for (int i = 0; i < count; i++)
            {
                sdcli.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Sealed Derived Class as Interface {sw.ElapsedMilliseconds}");

            sw.Restart();
            var comp = new ThisIsComposedClass();

            for (int i = 0; i < count; i++)
            {
                comp.Increment();
            }
            sw.Stop();
            Console.WriteLine($"Composed class {sw.ElapsedMilliseconds}");
        }
 public bool foo <S>(IIncrementable <S> y, T x)
 {
     return(y.Value() == x.Value());
 }
Exemple #9
0
 public Node(ulong key, IIncrementable <T> v)
 {
     Key  = key;
     Data = v;
     Next = null;
 }
Exemple #10
0
        public void CallVsCallVirt(int r)
        {
            var count = 100_000_000;

            // var sw = new Stopwatch();


            using (Benchmark.Run("Value", count))
            {
                int *ptr = stackalloc int[1];

                int intValue = 0;
                for (int i = 0; i < count; i++)
                {
                    *((int *)ptr) = *((int *)ptr) + 1;
                    intValue      = (*((int *)ptr));
                }
            }


            using (Benchmark.Run("Struct", count))
            {
                var str = new ThisIsSrtuct(new byte[4]);
                for (int i = 0; i < count; i++)
                {
                    str.Increment();
                }
            }

            using (Benchmark.Run("Str>Interface", count))
            {
                IIncrementable strAsInterface = (IIncrementable)(new ThisIsSrtuct(new byte[4]));
                for (int i = 0; i < count; i++)
                {
                    strAsInterface.Increment();
                }
            }

            using (Benchmark.Run("Str>Constr", count))
            {
                var constrainedStr = (new ThisIsSrtuct(new byte[4]));
                ConstrainedStruct(constrainedStr);
            }

            using (Benchmark.Run("Static Class", count))
            {
                for (int i = 0; i < count; i++)
                {
                    ThisIsStaticClass.Increment();
                }
            }

            using (Benchmark.Run("Class", count))
            {
                var cl = new ThisIsClass();
                for (int i = 0; i < count; i++)
                {
                    cl.Increment();
                }
            }

            using (Benchmark.Run("Class+Lock", count))
            {
                var cl_l = new ThisIsClassWithLock();
                for (int i = 0; i < count; i++)
                {
                    cl_l.Increment();
                }
            }

            using (Benchmark.Run("Class+MLock", count))
            {
                var cl_ml = new ThisIsClassWithManualLock();
                for (int i = 0; i < count; i++)
                {
                    cl_ml.Increment();
                }
            }

            using (Benchmark.Run("Sealed Class", count))
            {
                var scl = new ThisIsSealedClass();
                for (int i = 0; i < count; i++)
                {
                    scl.Increment();
                }
            }

            using (Benchmark.Run("Class>IFace", count))
            {
                IIncrementable cli = (IIncrementable) new ThisIsClass();
                for (int i = 0; i < count; i++)
                {
                    cli.Increment();
                }
            }

            using (Benchmark.Run("Derived Class", count))
            {
                var dcl = new ThisIsDerivedClass();
                for (int i = 0; i < count; i++)
                {
                    dcl.Increment();
                }
            }

            //sw.Restart();
            //IIncrementable dcli = (IIncrementable)new ThisIsDerivedClass();
            //for (int i = 0; i < count; i++)
            //{
            //    dcli.Increment();
            //}
            //sw.Stop();
            //Console.WriteLine($"Derived Class as Interface {sw.ElapsedMilliseconds}");

            //sw.Restart();
            //var sdcl = new ThisIsSealedDerivedClass();
            //for (int i = 0; i < count; i++)
            //{
            //    sdcl.Increment();
            //}
            //sw.Stop();
            //Console.WriteLine($"Sealed Derived Class {sw.ElapsedMilliseconds}");

            //sw.Restart();
            //IIncrementable sdcli = (IIncrementable)new ThisIsSealedDerivedClass();
            //for (int i = 0; i < count; i++)
            //{
            //    sdcli.Increment();
            //}
            //sw.Stop();
            //Console.WriteLine($"Sealed Derived Class as Interface {sw.ElapsedMilliseconds}");

            //sw.Restart();
            //var comp = new ThisIsComposedClass();
            //for (int i = 0; i < count; i++)
            //{
            //    comp.Increment();
            //}
            //sw.Stop();
            //Console.WriteLine($"Composed class {sw.ElapsedMilliseconds}");
        }