Exemplo n.º 1
0
            public static void RunCore(IHostApi hostApi, 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);
                // var dummyUnrollFactor = 1 << 6; // TODO: as arg to CreateDummy()?

                // 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 setupAction   = BenchmarkActionFactory.CreateSetup(target, instance);
                var cleanupAction = BenchmarkActionFactory.CreateCleanup(target, instance);
                var dummy1        = BenchmarkActionFactory.CreateDummy();
                var dummy2        = BenchmarkActionFactory.CreateDummy();
                var dummy3        = BenchmarkActionFactory.CreateDummy();

                FillProperties(instance, benchmark);

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

                var engineParameters = new EngineParameters
                {
                    //HostApi = hostApi,
                    IsDiagnoserAttached = hostApi.IsDiagnoserAttached,
                    MainAction          = mainAction.InvokeMultiple,
                    Dummy1Action        = dummy1.InvokeSingle,
                    Dummy2Action        = dummy2.InvokeSingle,
                    Dummy3Action        = dummy3.InvokeSingle,
                    IdleAction          = idleAction.InvokeMultiple,
                    SetupAction         = setupAction.InvokeSingle,
                    CleanupAction       = cleanupAction.InvokeSingle,
                    TargetJob           = job,
                    OperationsPerInvoke = target.OperationsPerInvoke
                };

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

                engine.PreAllocate();

                setupAction.InvokeSingle();

                if (job.ResolveValue(RunMode.RunStrategyCharacteristic, EngineResolver.Instance)
                    != RunStrategy.ColdStart)
                {
                    engine.Jitting();                     // does first call to main action, must be executed after setup()!
                }
                if (hostApi.IsDiagnoserAttached)
                {
                    hostApi.AfterSetup();
                }

                var results = engine.Run();

                if (hostApi.IsDiagnoserAttached)
                {
                    hostApi.BeforeCleanup();
                }
                cleanupAction.InvokeSingle();

                hostApi.Print(results);                 // printing costs memory, do this after runs
            }