Ejemplo n.º 1
0
        /// <summary>
        /// Runs the specified operation and returns the duration of time taken.
        /// </summary>
        /// <param name="container">The container to benchmark.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="tuple">The tuple.</param>
        /// <returns>
        /// A duration
        /// </returns>
        /// <exception cref="System.ArgumentException">Operation not supported - operation</exception>
        private Action <T> GetAction <T>(IBenchmarkContainer <T> container, BenchmarkOperation operation)
        {
            Action <T> method;

            switch (operation)
            {
            case BenchmarkOperation.Delete:
                method = container.Delete;
                break;

            case BenchmarkOperation.Find:
                method = (t) => container.Find(t);
                break;

            case BenchmarkOperation.Insert:
                method = container.Insert;
                break;

            case BenchmarkOperation.Iterate:
                method = (t) => container.Iterate();
                break;

            default:
                throw new ArgumentException("Operation not supported", nameof(operation));
            }

            return(method);
        }
        /// <summary>
        /// Called when starting.
        /// </summary>
        /// <returns>
        /// An asynchronous task
        /// </returns>
        public IEnumerable <BenchmarkResult> Run()
        {
            List <BenchmarkResult> results = new List <BenchmarkResult>();

            foreach (BenchmarkContainerType containerType in this.configuration.ContainerTypes)
            {
                foreach (long cardinality in this.configuration.Cardinalities)
                {
                    int[] containerData = Utilities.GetSlice(this.data, cardinality);

                    IBenchmarkContainer <int> container = BenchmarkContainerFactory <int> .CreateBenchmarkContainer(containerType, containerData);

                    BenchmarkResult result = this.runner.GetResult(container);
                    results.Add(result);
                }
            }

            return(results);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the results.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <returns>A benchmark result</returns>
        public BenchmarkResult GetResult(IBenchmarkContainer <int> container)
        {
            BenchmarkResult result = new BenchmarkResult(container.Type, container.Cardinality);

            int operationIndex = 0;

            foreach (KeyValuePair <BenchmarkOperation, int> kvp in this.configuration.Operations)
            {
                Action <int> action = this.GetAction(container, kvp.Key);

                this.stopWatch.Restart();
                for (int iterationIndex = 0; iterationIndex < (kvp.Value * this.configuration.TestIterationCountScalar); iterationIndex++)
                {
                    action(this.testValues[operationIndex + iterationIndex]);
                }
                this.stopWatch.Stop();

                result.Record(kvp.Key, this.scoringStrategy.Score(this.stopWatch.ElapsedMilliseconds));
                operationIndex++;
            }

            return(result);
        }