Exemple #1
0
        public static void Main(string[] args)
        {
#if DEBUG
            CompiledCodeGenerator.CompileCode();
            CompiledCodeGenerator.CompiledMethodParameters(1);
            CompiledCodeGenerator.CompiledMethodVoid();

            EmittedCodeGenerator.EmitCode();
            EmittedCodeGenerator.EmittedMethodParameters(1);
            EmittedCodeGenerator.EmittedMethodVoid();
#elif RELEASE
            BenchmarkRunner.Run <MethodParametersJob>();
            //BenchmarkRunner.Run<MethodVoidJob>();
#endif
        }
Exemple #2
0
        public void GlobalSetup()
        {
            _request      = 1;
            _staticMethod = typeof(StaticMethod).GetMethod(nameof(StaticMethod.Parameters));
            if (_staticMethod == null)
            {
                throw new InvalidOperationException("Could not get static method with parameters.");
            }

            // non-virtual
            _nonVirtualMethod = new NonVirtualMethod();

            // interface
            _interfaceMethod = new InterfaceMethod();

            // delegates
            _delegate = StaticMethod.Parameters;

            // reflection delegates
            _reflectionDelegate = (Func <int, int>)_staticMethod.CreateDelegate(typeof(Func <int, int>));

            // compiled expression tree
            int response = 1;
            Expression <Func <int, int> > expressionTree = request => response;

            _compiledExpressionTreeDelegate = expressionTree.Compile(preferInterpretation: false);

            // compiled code
            CompiledCodeGenerator.CompileCode();
            _compiledCodeDelegate = CompiledCodeGenerator.CompiledMethodParameters;

            // emitted code
            EmittedCodeGenerator.EmitCode();
            _emittedCodeDelegate = EmittedCodeGenerator.EmittedMethodParameters;

            // slow reflection
            _slowArgs = new object[] { 1 };
        }
        public void GlobalSetup()
        {
            _staticMethod = typeof(StaticMethod).GetMethod(nameof(StaticMethod.Void));
            if (_staticMethod == null)
            {
                throw new InvalidOperationException("Could not get static method void.");
            }

            // non-virtual
            _nonVirtualMethod = new NonVirtualMethod();

            // interface
            _interfaceMethod = new InterfaceMethod();

            // delegates
            _delegate = StaticMethod.Void;

            // reflection delegates
            _reflectionDelegate = (Action)_staticMethod.CreateDelegate(typeof(Action));

            // compiled expression tree
            Expression <Action> expressionTree = () => EmptyMethod();

            _compiledExpressionTreeDelegate = expressionTree.Compile(preferInterpretation: false);

            // compiled code
            CompiledCodeGenerator.CompileCode();
            _compiledCodeDelegate = CompiledCodeGenerator.CompiledMethodVoid;

            // emitted code
            EmittedCodeGenerator.EmitCode();
            _emittedCodeDelegate = EmittedCodeGenerator.EmittedMethodVoid;

            // slow reflection
            _slowArgs = new object[0];
        }