Esempio n. 1
0
            public static void RunCore(IHost host, Benchmark benchmark, BenchmarkActionCodegen codegenMode)
            {
                var target       = benchmark.Target;
                var job          = benchmark.Job; // TODO: filter job (same as SourceCodePresenter does)?
                var unrollFactor = benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance);

                // DONTTOUCH: these should be allocated together
                var instance               = Activator.CreateInstance(benchmark.Target.Type);
                var mainAction             = BenchmarkActionFactory.CreateRun(target, instance, codegenMode, unrollFactor);
                var idleAction             = BenchmarkActionFactory.CreateIdle(target, instance, codegenMode, unrollFactor);
                var globalSetupAction      = BenchmarkActionFactory.CreateGlobalSetup(target, instance);
                var globalCleanupAction    = BenchmarkActionFactory.CreateGlobalCleanup(target, instance);
                var iterationSetupAction   = BenchmarkActionFactory.CreateIterationSetup(target, instance);
                var iterationCleanupAction = BenchmarkActionFactory.CreateIterationCleanup(target, instance);
                var dummy1 = BenchmarkActionFactory.CreateDummy();
                var dummy2 = BenchmarkActionFactory.CreateDummy();
                var dummy3 = BenchmarkActionFactory.CreateDummy();

                FillMembers(instance, benchmark);

                host.WriteLine();
                foreach (var infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
                {
                    host.WriteLine("// {0}", infoLine);
                }
                host.WriteLine("// Job: {0}", job.DisplayInfo);
                host.WriteLine();

                var engineParameters = new EngineParameters
                {
                    Host                   = host,
                    MainAction             = mainAction.InvokeMultiple,
                    Dummy1Action           = dummy1.InvokeSingle,
                    Dummy2Action           = dummy2.InvokeSingle,
                    Dummy3Action           = dummy3.InvokeSingle,
                    IdleAction             = idleAction.InvokeMultiple,
                    GlobalSetupAction      = globalSetupAction.InvokeSingle,
                    GlobalCleanupAction    = globalCleanupAction.InvokeSingle,
                    IterationSetupAction   = iterationSetupAction.InvokeSingle,
                    IterationCleanupAction = iterationCleanupAction.InvokeSingle,
                    TargetJob              = job,
                    OperationsPerInvoke    = target.OperationsPerInvoke
                };

                var engine = job
                             .ResolveValue(InfrastructureMode.EngineFactoryCharacteristic, InfrastructureResolver.Instance)
                             .Create(engineParameters);

                engine.PreAllocate();

                globalSetupAction.InvokeSingle();
                iterationSetupAction.InvokeSingle();

                if (job.ResolveValue(RunMode.RunStrategyCharacteristic, EngineResolver.Instance).NeedsJitting())
                {
                    engine.Jitting(); // does first call to main action, must be executed after setup()!
                }
                iterationCleanupAction.InvokeSingle();

                if (host.IsDiagnoserAttached)
                {
                    host.AfterGlobalSetup();
                }

                var results = engine.Run();

                if (host.IsDiagnoserAttached)
                {
                    host.BeforeGlobalCleanup();
                }
                globalCleanupAction.InvokeSingle();

                host.ReportResults(results); // printing costs memory, do this after runs
            }