Esempio n. 1
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount     = data.InvokeCount;
            int  unrollFactor    = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            var  action          = data.IterationMode.IsIdle() ? IdleAction : MainAction;

            GcCollect();

            // Measure
            var clock = Clock.Start();

            action(invokeCount / unrollFactor);
            var clockSpan = clock.Stop();

            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.Index, totalOperations, clockSpan.GetNanoseconds());

            if (!IsDiagnoserAttached)
            {
                WriteLine(measurement.ToOutputLine());
            }

            return(measurement);
        }
Esempio n. 2
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount     = data.InvokeCount;
            int  unrollFactor    = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            var  action          = data.IterationMode.IsIdle() ? IdleAction : MainAction;

            // Setup
            SetupAction?.Invoke();
            GcCollect();

            // Measure
            var clock = TargetJob.Infrastructure.Clock.Resolve(Resolver).Start();

            action(invokeCount / unrollFactor);
            var clockSpan = clock.Stop();

            // Cleanup
            CleanupAction?.Invoke();
            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.Index, totalOperations, clockSpan.GetNanoseconds());

            WriteLine(measurement.ToOutputLine());
            return(measurement);
        }
 public Measurement RunIteration(IterationData data)
 {
     double nanoseconds = measure(data).Nanoseconds;
     var measurement = new Measurement(1, data.IterationMode, data.Index, data.InvokeCount * OperationsPerInvoke, nanoseconds);
     WriteLine(measurement.ToOutputLine());
     return measurement;
 }
Esempio n. 4
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount     = data.InvokeCount;
            int  unrollFactor    = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            bool isOverhead      = data.IterationMode == IterationMode.Overhead;
            bool randomizeMemory = !isOverhead && MemoryRandomization;
            var  action          = isOverhead ? OverheadAction : WorkloadAction;

            if (!isOverhead)
            {
                IterationSetupAction();
            }

            GcCollect();

            if (EngineEventSource.Log.IsEnabled())
            {
                EngineEventSource.Log.IterationStart(data.IterationMode, data.IterationStage, totalOperations);
            }

            Span <byte> stackMemory = randomizeMemory ? stackalloc byte[random.Next(32)] : Span <byte> .Empty;

            // Measure
            var clock = Clock.Start();

            action(invokeCount / unrollFactor);
            var clockSpan = clock.GetElapsed();

            if (EngineEventSource.Log.IsEnabled())
            {
                EngineEventSource.Log.IterationStop(data.IterationMode, data.IterationStage, totalOperations);
            }

            if (!isOverhead)
            {
                IterationCleanupAction();
            }

            if (randomizeMemory)
            {
                RandomizeManagedHeapMemory();
            }

            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.IterationStage, data.Index, totalOperations, clockSpan.GetNanoseconds());

            WriteLine(measurement.ToString());

            Consume(stackMemory);

            return(measurement);
        }
Esempio n. 5
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount     = data.InvokeCount;
            int  unrollFactor    = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            bool isOverhead      = data.IterationMode == IterationMode.Overhead;
            var  action          = isOverhead ? OverheadAction : WorkloadAction;

            if (!isOverhead)
            {
                IterationSetupAction();
            }

            GcCollect();

            if (EngineEventSource.Log.IsEnabled())
            {
                EngineEventSource.Log.IterationStart(data.IterationMode, data.IterationStage, totalOperations);
            }

            // Measure
            var clock = Clock.Start();

            action(invokeCount / unrollFactor);
            var clockSpan = clock.GetElapsed();

            if (EngineEventSource.Log.IsEnabled())
            {
                EngineEventSource.Log.IterationStop(data.IterationMode, data.IterationStage, totalOperations);
            }

            if (!isOverhead)
            {
                IterationCleanupAction();
            }

            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.IterationStage, data.Index, totalOperations, clockSpan.GetNanoseconds(), Encoding);

            WriteLine(measurement.ToOutputLine());

            return(measurement);
        }
Esempio n. 6
0
        private GcStats MeasureGcStats(IterationData data)
        {
            // we enable monitoring after main target run, for this single iteration which is executed at the end
            // so even if we enable AppDomain monitoring in separate process
            // it does not matter, because we have already obtained the results!
            EnableMonitoring();

            IterationSetupAction(); // we run iteration setup first, so even if it allocates, it is not included in the results

            var initialGcStats = GcStats.ReadInitial();

            MainAction(data.InvokeCount / data.UnrollFactor);

            var finalGcStats = GcStats.ReadFinal();

            IterationCleanupAction(); // we run iteration cleanup after collecting GC stats

            return((finalGcStats - initialGcStats).WithTotalOperations(data.InvokeCount * OperationsPerInvoke));
        }
Esempio n. 7
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount     = data.InvokeCount;
            int  unrollFactor    = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            bool isIdle          = data.IterationMode.IsIdle();
            var  action          = isIdle ? IdleAction : MainAction;

            if (!isIdle)
            {
                IterationSetupAction();
            }

            GcCollect();

            // Measure
            var clock = Clock.Start();

            action(invokeCount / unrollFactor);
            var clockSpan = clock.GetElapsed();

            if (!isIdle)
            {
                IterationCleanupAction();
            }

            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.Index, totalOperations, clockSpan.GetNanoseconds(), Encoding);

            WriteLine(measurement.ToOutputLine());

            return(measurement);
        }
Esempio n. 8
0
 /// <summary>Runs the iteration.</summary>
 /// <param name="data">The data.</param>
 /// <returns>Measurement for the iteration</returns>
 /// <exception cref="NotSupportedException"></exception>
 Measurement IEngine.RunIteration(IterationData data)
 {
     throw new NotSupportedException();
 }
 public Measurement RunIteration(IterationData data) { throw new NotImplementedException(); }
Esempio n. 10
0
        public Measurement RunIteration(IterationData data)
        {
            // Initialization
            long invokeCount = data.InvokeCount;
            int unrollFactor = data.UnrollFactor;
            long totalOperations = invokeCount * OperationsPerInvoke;
            var action = data.IterationMode.IsIdle() ? IdleAction : MainAction;

            GcCollect();

            // Measure
            var clock = Clock.Start();
            action(invokeCount / unrollFactor);
            var clockSpan = clock.Stop();

            GcCollect();

            // Results
            var measurement = new Measurement(0, data.IterationMode, data.Index, totalOperations, clockSpan.GetNanoseconds());
            if (!IsDiagnoserAttached) WriteLine(measurement.ToOutputLine());

            return measurement;
        }