Example #1
0
 internal override void HandleStartRun(BenchmarkOptions options)
 {
     foreach (var handler in handlers)
     {
         handler.HandleStartRun(options);
     }
 }
 internal override void HandleStartRun(BenchmarkOptions options)
 {
     Console.WriteLine("Environment: CLR {0} on {1}", Environment.Version, Environment.OSVersion);
     if (options.Label != null)
     {
         Console.WriteLine("Run label: {0}", options.Label);
     }
 }
 internal override void HandleStartRun(BenchmarkOptions options)
 {
     Console.WriteLine("Environment: CLR {0} on {1} ({2})", Environment.Version, Environment.OSVersion,
                       Environment.Is64BitProcess ? "64 bit" : "32 bit");
     if (options.Label != null)
     {
         Console.WriteLine("Run label: {0}", options.Label);
     }
 }
 internal override void HandleStartRun(BenchmarkOptions options)
 {
     document.Root.Add(new XElement("environment",
                                    new XAttribute("runtime", Environment.Version),
                                    new XAttribute("os", Environment.OSVersion),
                                    new XAttribute("cores", Environment.ProcessorCount),
                                    new XAttribute("is-64bit-process", Environment.Is64BitProcess),
                                    new XAttribute("is-64bit-os", Environment.Is64BitOperatingSystem),
                                    new XAttribute("machine", Environment.MachineName)));
     document.Root.Add(new XElement("options",
                                    new XAttribute("type-filter", options.TypeFilter ?? ""),
                                    new XAttribute("method-filter", options.MethodFilter ?? ""),
                                    new XAttribute("test-time", options.TestTime.ToTimeSpan()),
                                    new XAttribute("warmup-time", options.WarmUpTime.ToTimeSpan())));
     if (options.Label != null)
     {
         document.Root.Add(new XAttribute("label", options.Label));
     }
 }
        private static BenchmarkResult RunBenchmark(MethodInfo method, object instance, BenchmarkOptions options)
        {
            var action = (Action)Delegate.CreateDelegate(typeof(Action), instance, method);

            if (options.DryRunOnly)
            {
                action();
                return(new BenchmarkResult(method, 1, Duration.FromTicks(1)));
            }

            // Start small, double until we've hit our warm-up time
            int iterations = 100;

            while (true)
            {
                Duration duration = RunTest(action, iterations, options.Timer);
                if (duration >= options.WarmUpTime)
                {
                    // Scale up the iterations to work out the full test time
                    double scale            = ((double)options.TestTime.Ticks) / duration.Ticks;
                    double scaledIterations = scale * iterations;
                    // Make sure we never end up overflowing...
                    iterations = (int)Math.Min(scaledIterations, int.MaxValue - 1);
                    break;
                }
                // Make sure we don't end up overflowing due to doubling...
                if (iterations >= int.MaxValue / 2)
                {
                    break;
                }
                iterations *= 2;
            }
            Duration testDuration = RunTest(action, iterations, options.Timer);

            return(new BenchmarkResult(method, iterations, testDuration));
        }
 internal BenchmarkRunner(BenchmarkOptions options, BenchmarkResultHandler resultHandler)
 {
     this.options       = options;
     this.resultHandler = resultHandler;
 }
Example #7
0
 /// <summary>
 /// Called at the very start of the set of tests.
 /// </summary>
 /// <param name="options">Options used in this test</param>
 internal virtual void HandleStartRun(BenchmarkOptions options)
 {
 }