Esempio n. 1
0
        /// <summary>
        /// Executes the benchmarks.
        /// </summary>
        /// <param name="numOfThreads">The num of threads.</param>
        /// <param name="benchmarkType">Type of the benchmark.</param>
        /// <param name="constructorParameters">The constructor parameters.</param>
        /// <returns></returns>
        private static BenchmarkBase[] ExecuteBenchmarks(int numOfThreads, Type benchmarkType, params object[] constructorParameters) {
            BenchmarkBase[] benchmarks = new BenchmarkBase[numOfThreads];

            //Create threads
            Mutex mutex = new Mutex(true, Settings.MUTEX_NAME);

            #if THREADS
                Thread[] tasks = new Thread[numOfThreads];
            #else
                Task[] tasks = new Task[numOfThreads];
            #endif

            for (int i = 0; i < numOfThreads; i++) {
                benchmarks[i] = Activator.CreateInstance(benchmarkType, constructorParameters) as BenchmarkBase;

                #if THREADS
                    tasks[i] = new Thread(new ThreadStart(benchmarks[i].ExecuteBenchmark));
                #else
                    tasks[i] = new Task(new Action(benchmarks[i].ExecuteBenchmark));
                #endif
                tasks[i].Start();
            }

            //Start nechmark execution
            mutex.ReleaseMutex();
            mutex.Dispose();

            //Wait for threads to complete execution
            #if THREADS
                while (tasks.Any(t => t.IsAlive)) { }
            #else
                while (tasks.Any(t => !t.IsCompleted)) { }
            #endif

            return benchmarks;
        }
Esempio n. 2
0
 /// <summary>
 /// Appends the data table.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="benchmark">The benchmark.</param>
 private void AppendDataTable(DataTable data, string serverName, int run, BenchmarkBase benchmark)
 {
     if (benchmark.GetType() == typeof(CompositeQueries)) {
         AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).SimpleQuery);
         AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).FilterQuery);
         AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).TagCountMapReduce);
         AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).CommentAuthorMapReduce);
     }
     else {
         DataRow row = data.NewRow();
         row["Server"] = serverName;
         row["Run"] = run;
         row["Type"] = benchmark.Type;
         row["Time (seconds)"] = benchmark.Time.ElapsedMilliseconds / 1000.0;
         data.Rows.Add(row);
     }
 }