Inheritance: MonoBehaviour
        public virtual async Task <long> Add([NotNull] BenchmarkDto entity)
        {
            var newEntity = new Benchmark()
            {
                Name                  = entity.BenchmarkName,
                Description           = entity.Description,
                OwnerId               = entity.OwnerId,
                HtmlPreparationCode   = entity.HtmlPreparationCode,
                ScriptPreparationCode = entity.ScriptPreparationCode,
                BenchmarkTest         = new List <BenchmarkTest>()
            };

            foreach (var test in entity.TestCases)
            {
                var newTest = new BenchmarkTest()
                {
                    TestName      = test.TestCaseName,
                    BenchmarkText = test.BenchmarkCode,
                };
                newEntity.BenchmarkTest.Add(newTest);
            }

            this.Validate(newEntity);

            this.m_db.Benchmark.Add(newEntity);
            await this.m_db.SaveChangesAsync().ConfigureAwait(false);

            return(newEntity.Id);
        }
 protected override void Execute(BenchmarkTest test)
 {
     for (var i = 0; i < test.NTimes; i++)
     {
         test.Function.Invoke();
     }
 }
Example #3
0
        private void DoBenchmark()
        {
            BenchmarkSuite testSuite = new BenchmarkSuite();

            testSuite.OnTestFinish += Report;

            try
            {
                foreach (var benchmark in History)
                {
                    if (Cancellation.IsCancellationRequested)
                    {
                        break;
                    }

                    Current = benchmark;
                    testSuite.ExecuteInit(benchmark);

                    // Write.
                    ApplicationManager.SetCurrentMethod(TestMethod.Write);
                    CurrentStatus = TestMethod.Write.ToString();

                    testSuite.ExecuteWrite(benchmark);

                    // Read.
                    ApplicationManager.SetCurrentMethod(TestMethod.Read);
                    CurrentStatus = TestMethod.Read.ToString();

                    testSuite.ExecuteRead(benchmark);

                    // Secondary Read.
                    ApplicationManager.SetCurrentMethod(TestMethod.SecondaryRead);
                    CurrentStatus = TestMethod.SecondaryRead.ToString();

                    testSuite.ExecuteSecondaryRead(benchmark);

                    // Finish.
                    CurrentStatus = TestMethod.None.ToString();
                    testSuite.ExecuteFinish(benchmark);
                }
            }
            finally
            {
                Current = null;

                if (Cancellation.IsCancellationRequested)
                {
                    History.Clear();
                }
                else
                {
                    if (!(bool)Properties.Settings.Default["HideReportForm"])
                    {
                        StartOnlineReport();
                    }
                }
            }
        }
        public void Test(BenchmarkTest test)
        {
            var timer = Stopwatch.StartNew();

            timer.Start();
            Execute(test);
            timer.Stop();
            test.Duration = timer.ElapsedMilliseconds;
        }
Example #5
0
 private void EventSelectedIndexChanged(object sender, EventArgs e)
 {
     if (ReferenceEquals(sender, cbTest))
     {
         BenchmarkTest benchmark = cbTest.SelectedItem as BenchmarkTest;
         lbSingleThreadDevResults.Text = $"Single Thread: {benchmark.DevSingleThreadResult} {RunsAbbreviation}";
         lbMultiThreadDevResults.Text  = $"Multi Thread: {benchmark.DevMultiThreadResult} {RunsAbbreviation}";
         return;
     }
 }
Example #6
0
 public void execute(BenchmarkTest test)
 {
     // clear previous results
     for (int i = 0; i < timers.Length; i++)
         timers[i] = null;
     // loop for the specified number of iterations or until the time limit
     long startTime = NanoTime.Now;
     for (int i = 0; i < timers.Length && ((NanoTime.Now - startTime) / 1000000000) < timeLimit; i++)
     {
         UI.printInfo(UI.Module.BENCH, "Running iteration {0}", (i + 1));
         timers[i] = new Timer();
         test.kernelBegin();
         timers[i].start();
         test.kernelMain();
         timers[i].end();
         test.kernelEnd();
     }
     // report stats
     double avg = 0;
     double min = double.PositiveInfinity;
     double max = double.NegativeInfinity;
     int n = 0;
     foreach (Timer t in timers)
     {
         if (t == null)
             break;
         double s = t.seconds();
         min = Math.Min(min, s);
         max = Math.Max(max, s);
         avg += s;
         n++;
     }
     if (n == 0)
         return;
     avg /= n;
     double stdDev = 0;
     foreach (Timer t in timers)
     {
         if (t == null)
             break;
         double s = t.seconds();
         stdDev += (s - avg) * (s - avg);
     }
     stdDev = Math.Sqrt(stdDev / n);
     UI.printInfo(UI.Module.BENCH, "Benchmark results:");
     UI.printInfo(UI.Module.BENCH, "  * Iterations: {0}", n);
     UI.printInfo(UI.Module.BENCH, "  * Average:    {0}", Timer.tostring(avg));
     UI.printInfo(UI.Module.BENCH, "  * Fastest:    {0}", Timer.tostring(min));
     UI.printInfo(UI.Module.BENCH, "  * Longest:    {0}", Timer.tostring(max));
     UI.printInfo(UI.Module.BENCH, "  * Deviation:  {0}", Timer.tostring(stdDev));
     for (int i = 0; i < timers.Length && timers[i] != null; i++)
         UI.printDetailed(UI.Module.BENCH, "  * Iteration {0}: {1}", i + 1, timers[i]);
 }
Example #7
0
 private void makeTestToggles(int indexStart, int indexEnd)
 {
     using (new GUILayout.VerticalScope())
     {
         for (int i = indexStart; i < indexEnd; i++)
         {
             GUILayout.Space(10f);
             BenchmarkTest benchmarkTest = Config.Tests[i];
             activeTests[i] = GUILayout.Toggle(activeTests[i], benchmarkTest.name);
             GUILayout.Space(10f);
         }
     }
 }
        public static void ExportSettings(StreamWriter writer, BenchmarkTest session)
        {
            int    tableCount  = session.FlowCount;
            long   recordCount = session.RecordCount;
            string sequential  = session.KeysType.ToString();
            string randomness  = string.Format("{0}%", session.Randomness * 100);

            writer.WriteLine("Settings:");
            writer.WriteLine("Table count;Record count;Keys type;Randomness");
            writer.Write(tableCount + ";");
            writer.Write(recordCount + ";");
            writer.Write(sequential + ";");
            writer.WriteLine(randomness + ";");
        }
Example #9
0
        public string ProcessBenchmark(CollectorCommand command)
        {
            try
            {
                var benchmark = new BenchmarkTest(command.ThreadsCount);
                benchmark.AddLoadTestFactory(CreateReaderTest(ReadJsonFile(command.FileName), command.TableName,
                                                              command.HashFileName, command.CountReplics, command.PageSize));

                benchmark.Run();
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(string.Empty);
        }
Example #10
0
        private void startButton_Click(object sender, EventArgs e)
        {
            // Parse test parameters.
            TableCount  = Int32.Parse(cbFlowsCount.Text.Replace(" ", ""));
            RecordCount = Int64.Parse(cbRecordCount.Text.Replace(" ", ""));
            Randomness  = trackBar1.Value / 20.0f;

            var databases = ApplicationManager.SelectedDatabases;

            if (databases.Length == 0)
            {
                return;
            }

            History.Clear();
            Cancellation = new CancellationTokenSource();

            foreach (var database in databases)
            {
                var session = new BenchmarkTest(database, TableCount, RecordCount, Randomness, Cancellation);
                History.Add(session);

                try
                {
                    foreach (var directory in Directory.GetDirectories(database.DataDirectory))
                    {
                        Directory.Delete(directory, true);
                    }

                    foreach (var files in Directory.GetFiles(database.DataDirectory, "*.*", SearchOption.AllDirectories))
                    {
                        File.Delete(files);
                    }
                }
                catch (Exception exc)
                {
                    Logger.Error("Application exception occured...", exc);
                }
            }

            ApplicationManager.Prepare();

            // Start the benchmark.
            MainTask = Task.Factory.StartNew(DoBenchmark, Cancellation.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Example #11
0
        private void Export(ReportFormat reportFormat, ReportType reportType, SaveFileDialog dialog)
        {
            dialog.FileName = String.Format("Database Benchmark {0:yyyy-MM-dd HH.mm}", DateTime.Now);

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    // Start loading and disable MainForm.
                    LoadingForm.Start(string.Format("Exporting to {0} ....", reportFormat), Bounds);
                    Enabled = false;

                    switch (reportFormat)
                    {
                    case ReportFormat.CSV:
                        CsvUtils.ExportResults(History, saveFileDialogCsv.FileName, reportType);
                        break;

                    case ReportFormat.JSON:
                        ComputerConfiguration configuration = SystemUtils.GetComputerConfiguration();
                        JsonUtils.ExportToJson(saveFileDialogJson.FileName, configuration, History, reportType);
                        break;

                    case ReportFormat.PDF:
                        BenchmarkTest test = History[0];
                        PdfUtils.Export(saveFileDialogPdf.FileName, ApplicationManager.StepFrames, test.FlowCount, test.RecordCount, test.Randomness, SystemUtils.GetComputerConfiguration(), reportType);
                        break;
                    }

                    // Stop loading end enable MainForm
                    LoadingForm.Stop();
                    Enabled = true;
                }
                catch (Exception exc)
                {
                    string message = string.Format("Export results to {0} failed...", reportFormat);

                    Logger.Error(message, exc);
                    ReportError(message);
                    Enabled = true;
                    LoadingForm.Stop();
                }
            }
        }
        public void TestsFileSystemDataFeedSpeed()
        {
            var job                = new BacktestNodePacket();
            var resultHandler      = new BacktestingResultHandler();
            var mapFileProvider    = new LocalDiskMapFileProvider();
            var factorFileProvider = new LocalDiskFactorFileProvider(mapFileProvider);
            var dataProvider       = new DefaultDataProvider();

            var algorithm = new BenchmarkTest();
            var feed      = new FileSystemDataFeed();

            feed.Initialize(algorithm, job, resultHandler, mapFileProvider, factorFileProvider, dataProvider);
            algorithm.Initialize();

            var feedThreadStarted = new ManualResetEvent(false);

            Task.Factory.StartNew(() =>
            {
                feedThreadStarted.Set();
                feed.Run();
            });
            feedThreadStarted.WaitOne();

            var stopwatch = Stopwatch.StartNew();
            var lastMonth = -1;
            var count     = 0;

            foreach (var timeSlice in feed)
            {
                if (timeSlice.Time.Month != lastMonth)
                {
                    Console.WriteLine(DateTime.Now + " - Time: " + timeSlice.Time);
                    lastMonth = timeSlice.Time.Month;
                }
                count++;
            }
            Console.WriteLine("Count: " + count);

            stopwatch.Stop();
            Console.WriteLine("Elapsed time: " + stopwatch.Elapsed);
        }
        public static void ExportSummaryTestResults(List <BenchmarkTest> sessions, string path)
        {
            // ---Write Summary File---
            //#time
            //#database;write speed (rec/sec);read speed;secondary read speed;size (MB)

            string extension = ".csv";

            string[] fullPath        = path.Split(new string[] { extension }, StringSplitOptions.None);
            string   summaryFileName = fullPath[0] + ".summary" + extension;

            using (StreamWriter writer = new StreamWriter(summaryFileName))
            {
                // write settings
                ExportSettings(writer, sessions[0]);

                // write computer configuration
                writer.WriteLine();
                ExportComputerConfiguration(writer, SystemUtils.GetComputerConfiguration());

                writer.WriteLine();

                // write date
                writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH.mm"));
                writer.WriteLine();

                writer.WriteLine(String.Join(";", "Database;Write speed(rec/sec);Read speed(rec/sec);Seconady read speed(rec/sec);Size(MB)"));

                for (int i = 0; i < sessions.Count; i++)
                {
                    BenchmarkTest test = sessions[i];

                    // write database info
                    writer.Write(test.Database.Name + ";");
                    writer.Write(test.GetSpeed(TestMethod.Write) + ";");
                    writer.Write(test.GetSpeed(TestMethod.Read) + ";");
                    writer.Write(test.GetSpeed(TestMethod.SecondaryRead) + ";");
                    writer.WriteLine(test.DatabaseSize / (1024.0 * 1024.0) + ";");
                }
            }
        }
Example #14
0
        private void Report(BenchmarkTest benchmark, TestMethod method)
        {
            try
            {
                Action <string, object, Color> updateChart = null;

                StepFrame ActiveStepFrame = ApplicationManager.GetCurrentStepFrame();
                string    databaseName    = benchmark.Database.Name;
                Color     databaseColor   = benchmark.Database.Color;

                // Speed chart.
                updateChart = ActiveStepFrame.AddAverageSpeedToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.GetSpeed(method));

                // Size chart.
                updateChart = ActiveStepFrame.AddSizeToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.DatabaseSize / (1024.0 * 1024.0));

                // Time chart.
                updateChart = ActiveStepFrame.AddTimeToBar;
                Report(databaseName, databaseColor, updateChart, new DateTime(benchmark.GetTime(method).Ticks));

                // CPU chart.
                //updateChart = ActiveStepFrame.AddCpuUsageToBar;
                //Report(databaseName, databaseColor, updateChart, benchmark.GetAverageProcessorTime(method));

                // Memory chart.
                updateChart = ActiveStepFrame.AddMemoryUsageToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.GetPeakWorkingSet(method) / (1024.0 * 1024.0));

                // I/O chart.
                //updateChart = ActiveStepFrame.AddIoUsageToBar;
                //Report(databaseName, databaseColor, updateChart, benchmark.GetAverageIOData(method) / (1024.0 * 1024.0));
            }
            catch (Exception exc)
            {
                Logger.Error("Report results failed...", exc);
            }
        }
        public void TestsFileSystemDataFeedSpeed()
        {
            var job = new BacktestNodePacket();
            var resultHandler = new BacktestingResultHandler();
            var mapFileProvider = new LocalDiskMapFileProvider();
            var factorFileProvider = new LocalDiskFactorFileProvider(mapFileProvider);
            var dataFileProvider = new DefaultDataFileProvider();

            var algorithm = new BenchmarkTest();
            var feed = new FileSystemDataFeed();

            feed.Initialize(algorithm, job, resultHandler, mapFileProvider, factorFileProvider, dataFileProvider);
            algorithm.Initialize();

            var feedThreadStarted = new ManualResetEvent(false);
            Task.Factory.StartNew(() =>
            {
                feedThreadStarted.Set();
                feed.Run();
            });
            feedThreadStarted.WaitOne();

            var stopwatch = Stopwatch.StartNew();
            var lastMonth = -1;
            var count = 0;
            foreach (var timeSlice in feed)
            {
                if (timeSlice.Time.Month != lastMonth)
                {
                    Console.WriteLine(DateTime.Now + " - Time: " + timeSlice.Time);
                    lastMonth = timeSlice.Time.Month;
                }
                count++;
            }
            Console.WriteLine("Count: " + count);

            stopwatch.Stop();
            Console.WriteLine("Elapsed time: " + stopwatch.Elapsed);
        }
Example #16
0
        public string ProcessBenchmark(WriterCommand command)
        {
            try
            {
                var benchmark = new BenchmarkTest(command.ThreadsCount, command.DataCount);

                var testTypes = ParseTestTypes(command.TestType,
                                               () => new DbWriterAdapter(command.Host, command.Port, command.TableName),
                                               command.Generator, new KeyGenerator(command.KeyRange));
                foreach (var func in testTypes)
                {
                    benchmark.AddLoadTestFactory(func);
                }

                benchmark.Run();
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(string.Empty);
        }
Example #17
0
        public void PlusReturnValueAddsTest()
        {
            BenchmarkTest <int, int> test = new BenchmarkTest <int, int>(x => x, "foo");

            Assert.AreSame(test, EmptySuite.Plus(test).First());
        }
Example #18
0
        public static int Main(string[] args)
        {
            List <string> temp = new List <string>(args);

            Verbose      = temp.Remove("/verbose") || temp.Remove("-verbose");
            OtherFormats = temp.Remove("/formats") || temp.Remove("-formats");

            foreach (string arg in temp)
            {
                if (arg.StartsWith("/log:", StringComparison.OrdinalIgnoreCase) || arg.StartsWith("-log:", StringComparison.OrdinalIgnoreCase))
                {
                    _logFile = arg.Substring(5);
                    if (!String.IsNullOrEmpty(_logFile))
                    {
                        File.AppendAllText(_logFile, Environment.NewLine + "Started benchmarks at " + DateTime.Now + Environment.NewLine);
                    }
                    temp.Remove(arg);
                    break;
                }
            }

            if (true == (FastTest = (temp.Remove("/fast") || temp.Remove("-fast"))))
            {
                TargetTime = TimeSpan.FromSeconds(10);
            }

            RunBenchmark = BenchmarkV1;
            if (temp.Remove("/v2") || temp.Remove("-v2"))
            {
                Process.GetCurrentProcess().PriorityClass     = ProcessPriorityClass.RealTime;
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(1);
                RunBenchmark = BenchmarkV2;
            }
            if (temp.Remove("/all") || temp.Remove("-all"))
            {
                if (FastTest)
                {
                    TargetTime = TimeSpan.FromSeconds(5);
                }
                foreach (KeyValuePair <string, string> item in MakeTests())
                {
                    temp.Add(item.Key);
                    temp.Add(item.Value);
                }
            }
            args = temp.ToArray();

            if (args.Length < 2 || (args.Length % 2) != 0)
            {
                Console.Error.WriteLine("Usage: ProtoBench [/fast] <descriptor type name> <input data>");
                Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
                Console.Error.WriteLine(
                    "including assembly - e.g. Google.ProtocolBuffers.BenchmarkProtos.Message1,ProtoBench");
                Console.Error.WriteLine("(You can specify multiple pairs of descriptor type name and input data.)");
                return(1);
            }

            bool success = true;

            for (int i = 0; i < args.Length; i += 2)
            {
                success &= RunTest(args[i], args[i + 1], null);
            }
            return(success ? 0 : 1);
        }
Example #19
0
        private void StartBenchmark()
        {
            if (!btnStart.Enabled)
            {
                return;
            }
            cbTest.Enabled       =
                btnStart.Enabled = false;
            btnStop.Enabled      = true;

            TokenSource = new CancellationTokenSource();

            progressBar.Style = ProgressBarStyle.Marquee;

            BenchmarkTest benchmark = cbTest.SelectedItem as BenchmarkTest;
            MethodInfo    theMethod = GetType().GetMethod(benchmark.FunctionName);

            if (!benchmark.Name.Equals(StressCPUTestName))
            {
                lbSingleThreadResults.Text = $"Single Thread: Running {SingleThreadTests} tests";
                lbMultiThreadResults.Text  = $"Multi Thread: Running {MultiThreadTests} tests";
            }


            Task.Factory.StartNew(() =>
            {
                try
                {
                    if (benchmark.Name.Equals(StressCPUTestName))
                    {
                        while (true)
                        {
                            if (Token.IsCancellationRequested)
                            {
                                break;
                            }
                            Parallel.For(0, MultiThreadTests, i =>
                            {
                                if (Token.IsCancellationRequested)
                                {
                                    return;
                                }
                                theMethod.Invoke(this, null);
                            });
                        }

                        return;
                    }

                    Stopwatch sw = Stopwatch.StartNew();
                    for (int i = 0; i < SingleThreadTests; i++)
                    {
                        if (Token.IsCancellationRequested)
                        {
                            Token.ThrowIfCancellationRequested();
                        }
                        theMethod.Invoke(this, null);
                    }

                    sw.Stop();
                    Invoke((MethodInvoker) delegate
                    {
                        // Running on the UI thread
                        UpdateResults(true, sw.ElapsedMilliseconds);
                    });

                    if (Token.IsCancellationRequested)
                    {
                        Token.ThrowIfCancellationRequested();
                    }

                    sw.Restart();
                    Parallel.For(0, MultiThreadTests, i =>
                    {
                        if (Token.IsCancellationRequested)
                        {
                            return;
                        }
                        theMethod.Invoke(this, null);
                    });

                    sw.Stop();

                    if (Token.IsCancellationRequested)
                    {
                        Token.ThrowIfCancellationRequested();
                    }

                    Invoke((MethodInvoker) delegate
                    {
                        // Running on the UI thread
                        UpdateResults(false, sw.ElapsedMilliseconds);
                    });
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Invoke((MethodInvoker)StopBenchmark);
                }
            }, Token);
        }
Example #20
0
        public static void Main(string[] args)
        {
            string filePath   = "";
            int    sampleSize = -1;
            int    dbSize     = -1;
            double minSupport = -1;
            int    k          = -1;
            bool   help       = false;
            bool   benchmark  = false;
            long   killTime   = int.MaxValue;

            OptionSet p = new OptionSet();

            p.Add("f|file=", "Source data file {PATH}.", arg => filePath = arg);
            p.Add("b|benchmark", "Benchmark performance.", arg => { if (arg != null)
                                                                    {
                                                                        benchmark = true;
                                                                    }
                  });
            p.Add("s|support=", "Minimum pattern {SUPPORT}.", arg => { if (arg != null)
                                                                       {
                                                                           minSupport = double.Parse(arg);
                                                                       }
                  });
            p.Add("z|size=", "Sample {SIZE}.", arg => { if (arg != null)
                                                        {
                                                            sampleSize = int.Parse(arg);
                                                        }
                  });
            p.Add("d|db-size=", "Database {SIZE}.", arg => { if (arg != null)
                                                             {
                                                                 dbSize = int.Parse(arg);
                                                             }
                  });
            p.Add("k|top-k=", "Mine top-{K} sequences.", arg => { if (arg != null)
                                                                  {
                                                                      k = int.Parse(arg);
                                                                  }
                  });
            p.Add("kill=", "Stop program after {TIME} miliseconds", arg => { if (arg != null)
                                                                             {
                                                                                 killTime = int.Parse(arg);
                                                                             }
                  });
            p.Add("?|h|help", "Show this message and exit.", arg => { if (arg != null)
                                                                      {
                                                                          help = true;
                                                                      }
                  });

            try
            {
                p.Parse(args);
            }
            catch {}

            if (benchmark && filePath != "" && sampleSize >= 500 && dbSize > 0)
            {
                List <double> minSupports = new List <double>();
                minSupports.Add(0.01);
                minSupports.Add(0.025);
                minSupports.Add(0.05);
                minSupports.Add(0.1);

                // TODO: use top-k here
                BenchmarkTest.StartBenchmark(filePath, minSupports, new List <int>(), sampleSize, dbSize);
            }
            else if (!help && filePath != "" && (minSupport > 0 || k > 0) && sampleSize >= 500 && dbSize > 0)
            {
                if (k > 0 && minSupport > 0)
                {
                    printHelp(p);
                }
                else
                {
                    Console.WriteLine("Kill-after: " + killTime);
                    processFile(filePath, minSupport, k, k > 0, sampleSize, dbSize, killTime).Wait();
                }
            }
            else
            {
                printHelp(p);
            }
        }
Example #21
0
        public void execute(BenchmarkTest test)
        {
            // clear previous results
            for (int i = 0; i < timers.Length; i++)
            {
                timers[i] = null;
            }
            // loop for the specified number of iterations or until the time limit
            long startTime = NanoTime.Now;

            for (int i = 0; i < timers.Length && ((NanoTime.Now - startTime) / 1000000000) < timeLimit; i++)
            {
                UI.printInfo(UI.Module.BENCH, "Running iteration {0}", (i + 1));
                timers[i] = new Timer();
                test.kernelBegin();
                timers[i].start();
                test.kernelMain();
                timers[i].end();
                test.kernelEnd();
            }
            // report stats
            double avg = 0;
            double min = double.PositiveInfinity;
            double max = double.NegativeInfinity;
            int    n   = 0;

            foreach (Timer t in timers)
            {
                if (t == null)
                {
                    break;
                }
                double s = t.seconds();
                min  = Math.Min(min, s);
                max  = Math.Max(max, s);
                avg += s;
                n++;
            }
            if (n == 0)
            {
                return;
            }
            avg /= n;
            double stdDev = 0;

            foreach (Timer t in timers)
            {
                if (t == null)
                {
                    break;
                }
                double s = t.seconds();
                stdDev += (s - avg) * (s - avg);
            }
            stdDev = Math.Sqrt(stdDev / n);
            UI.printInfo(UI.Module.BENCH, "Benchmark results:");
            UI.printInfo(UI.Module.BENCH, "  * Iterations: {0}", n);
            UI.printInfo(UI.Module.BENCH, "  * Average:    {0}", Timer.tostring(avg));
            UI.printInfo(UI.Module.BENCH, "  * Fastest:    {0}", Timer.tostring(min));
            UI.printInfo(UI.Module.BENCH, "  * Longest:    {0}", Timer.tostring(max));
            UI.printInfo(UI.Module.BENCH, "  * Deviation:  {0}", Timer.tostring(stdDev));
            for (int i = 0; i < timers.Length && timers[i] != null; i++)
            {
                UI.printDetailed(UI.Module.BENCH, "  * Iteration {0}: {1}", i + 1, timers[i]);
            }
        }
Example #22
0
        public static JsonObjectCollection ConvertToJson(BenchmarkTest benchmark, ReportType type)
        {
            JsonObjectCollection jsonBenchmark = new JsonObjectCollection("BenchmarkTest");

            // Test info parameters.
            JsonObjectCollection jsonSettings = new JsonObjectCollection("TestInfo");

            jsonSettings.Add(new JsonNumericValue("FlowCount", benchmark.FlowCount));
            jsonSettings.Add(new JsonNumericValue("RecordCount", benchmark.RecordCount));
            jsonSettings.Add(new JsonNumericValue("Randomness", benchmark.Randomness * 100));

            long elapsedTime = benchmark.EndTime.Ticks - benchmark.StartTime.Ticks;

            jsonSettings.Add(new JsonNumericValue("ElapsedTime", new TimeSpan(elapsedTime).TotalMilliseconds));

            JsonObjectCollection jsonDatabase = new JsonObjectCollection("Database");

            jsonDatabase.Add(new JsonStringValue("Name", benchmark.Database.Name));
            jsonDatabase.Add(new JsonStringValue("IndexingTechnology", benchmark.Database.IndexingTechnology.ToString()));
            jsonDatabase.Add(new JsonStringValue("Category", benchmark.Database.Name));

            jsonDatabase.Add(new JsonNumericValue("AverageWriteSpeed", benchmark.GetSpeed(TestMethod.Write)));
            jsonDatabase.Add(new JsonNumericValue("AverageReadSpeed", benchmark.GetSpeed(TestMethod.Read)));
            jsonDatabase.Add(new JsonNumericValue("AverageSecondaryReadSpeed", benchmark.GetSpeed(TestMethod.SecondaryRead)));

            jsonDatabase.Add(new JsonNumericValue("WritePeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.Write) / (1024.0 * 1024.0)));
            jsonDatabase.Add(new JsonNumericValue("ReadPeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.Read) / (1024.0 * 1024.0)));
            jsonDatabase.Add(new JsonNumericValue("SecondaryReadPeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.SecondaryRead) / (1024.0 * 1024.0)));

            jsonDatabase.Add(new JsonNumericValue("Size", benchmark.DatabaseSize / (1024.0 * 1024.0)));

            JsonObjectCollection jsonDatabaseSettings = new JsonObjectCollection("Settings");

            if (benchmark.Database.Settings != null)
            {
                foreach (var item in benchmark.Database.Settings)
                {
                    jsonDatabaseSettings.Add(new JsonStringValue(item.Key, item.Value));
                }
            }

            jsonDatabase.Add(jsonDatabaseSettings);

            // Test results.
            JsonObjectCollection jsonTestData      = new JsonObjectCollection("TestResults");
            JsonObject           jsonWrite         = null;
            JsonObject           jsonRead          = null;
            JsonObject           jsonSecondaryRead = null;

            if (type == ReportType.Summary)
            {
                jsonWrite         = new JsonNumericValue("Write", benchmark.GetSpeed(TestMethod.Write));
                jsonRead          = new JsonNumericValue("Read", benchmark.GetSpeed(TestMethod.Read));
                jsonSecondaryRead = new JsonNumericValue("SecondaryRead", benchmark.GetSpeed(TestMethod.SecondaryRead));
            }
            else // type == ReportType.Detailed
            {
                // Get statistics and convert them to JSON.
                SpeedStatistics writeStat         = benchmark.SpeedStatistics[(int)TestMethod.Write];
                SpeedStatistics readStat          = benchmark.SpeedStatistics[(int)TestMethod.Read];
                SpeedStatistics secondaryReadStat = benchmark.SpeedStatistics[(int)TestMethod.SecondaryRead];

                jsonWrite         = ConvertStatisticToJson(writeStat, "Write");
                jsonRead          = ConvertStatisticToJson(readStat, "Read");
                jsonSecondaryRead = ConvertStatisticToJson(secondaryReadStat, "SecondaryRead");
            }

            jsonTestData.Add(jsonWrite);
            jsonTestData.Add(jsonRead);
            jsonTestData.Add(jsonSecondaryRead);

            // Form the end JSON structure.
            jsonBenchmark.Add(jsonSettings);
            jsonBenchmark.Add(jsonDatabase);
            jsonBenchmark.Add(jsonTestData);

            return(jsonBenchmark);
        }
 protected abstract void Execute(BenchmarkTest test);
 protected override void Execute(BenchmarkTest test)
 {
     Parallel.For(0, test.NTimes, i => test.Function.Invoke());
 }
        public static void ExportDetailedTestResults(List <BenchmarkTest> sessions, string path)
        {
            if (sessions.Count == 0)
            {
                return;
            }

            // ---Write Detailed Results File---

            using (StreamWriter writer = new StreamWriter(path))
            {
                // write settings
                ExportSettings(writer, sessions[0]);

                // write computer configuration
                writer.WriteLine();
                ExportComputerConfiguration(writer, SystemUtils.GetComputerConfiguration());

                writer.WriteLine();

                // write databases
                writer.WriteLine(String.Join(";;;;;;;;;;;", sessions.Select(x => x.Database.Name)));
                writer.WriteLine(String.Join(";", Enumerable.Repeat("Records;Write time;Read time;Secondary read time;Average write;Average read;Average secondary read;Moment write;Moment read;Moment secondary read;", sessions.Count)));

                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < BenchmarkTest.INTERVAL_COUNT; i++)
                {
                    for (int k = 0; k < sessions.Count; k++)
                    {
                        BenchmarkTest session = sessions[k];

                        // get statistics
                        SpeedStatistics writeStat         = session.SpeedStatistics[(int)TestMethod.Write];
                        SpeedStatistics readStat          = session.SpeedStatistics[(int)TestMethod.Read];
                        SpeedStatistics secondaryReadStat = session.SpeedStatistics[(int)TestMethod.SecondaryRead];

                        // calculate average speeds
                        var avgWriteSpeed         = writeStat.GetAverageSpeedAt(i);
                        var avgReadSpeed          = readStat.GetAverageSpeedAt(i);
                        var avgSecondaryReadSpeed = secondaryReadStat.GetAverageSpeedAt(i);

                        // calculate moment speeds
                        var momentWriteSpeed         = writeStat.GetMomentSpeedAt(i);
                        var momentReadSpeed          = readStat.GetMomentSpeedAt(i);
                        var momentSecondaryReadSpeed = secondaryReadStat.GetMomentSpeedAt(i);

                        // number of records & write timespan
                        var rec = writeStat.GetRecordAt(i);
                        builder.AppendFormat("{0};{1};", rec.Key, rec.Value.TotalMilliseconds);

                        // read timespan
                        rec = readStat.GetRecordAt(i);
                        builder.AppendFormat("{0};", rec.Value.TotalMilliseconds);

                        // secondary read timespan
                        rec = secondaryReadStat.GetRecordAt(i);
                        builder.AppendFormat("{0};", rec.Value.TotalMilliseconds);

                        // speeds
                        builder.Append(avgWriteSpeed + ";");
                        builder.Append(avgReadSpeed + ";");
                        builder.Append(avgSecondaryReadSpeed + ";");
                        builder.Append(momentWriteSpeed + ";");
                        builder.Append(momentReadSpeed + ";");
                        builder.Append(momentSecondaryReadSpeed + ";");
                        builder.Append(";");
                    }

                    writer.WriteLine(builder.ToString());
                    builder.Clear();
                }

                // write size
                writer.WriteLine();
                writer.WriteLine(String.Join(";;;;;;;;;;;", Enumerable.Repeat("Size(MB)", sessions.Count)));
                writer.WriteLine(String.Join(";;;;;;;;;;;", sessions.Select(x => x.Database.Size / (1024.0 * 1024.0))));
            }
        }
Example #26
0
 public void PlusReturnValueAddsTest()
 {
     BenchmarkTest<int, int> test = new BenchmarkTest<int, int>(x => x, "foo");
     Assert.AreSame(test, EmptySuite.Plus(test).First());
 }