static void Main(string[] args)
        {
            // cmd line params variables
            string dbConnStr         = null;
            int    runID             = 0;
            int    benchmarkMethodID = 0;
            int    n;
            int    maxN;

            try
            {
                DateTime startTime = DateTime.Now;
                //Console.WriteLine($"Args Count:" + args.Length.ToString());
                //foreach (string s in args)
                //{
                //	Console.WriteLine(s);
                //}
                //Console.ReadKey();

                string errMsg = PerfUtil.GetCmdLineParams_DbNAndMaxN(args, out dbConnStr, out runID, out benchmarkMethodID, out n, out maxN);
                //if (errMsg != null)
                //{
                //	Console.WriteLine(errMsg);
                //}
                //Console.WriteLine($"Args: {dbConnStr}; {runID.ToString()}; {benchmarkMethodID.ToString()}; {n.ToString()}; {maxN.ToString()}");
                //Console.ReadKey();

                int[] a;
                int[] c;

                HashSet <int> set = new HashSet <int>();

                BenchUtil.PopulateArrays25_25_50PctUnique(maxN, out a, out c);

                // in a real world scenario, we will have probably have recently added the items into the set, so no need to try to clear the cache or anything
                for (int i = 0; i < maxN; i++)
                {
                    set.Add(a[i]);
                }

                double overheadNanoSecs = PerfUtil.GetTimestampOverheadInNanoSeconds();

                PerfUtil.DoGCCollect();

                int    iterations = 1;
                long   startTicks;
                long   endTicks;
                double ticks;

                // this is enough to jit things and not put everything in the cache
                bool isContained = set.Contains(0);

                if (maxN <= 1000)
                {
                    iterations = 1;

                    // there amount of time taken for these is too small to measure just one iteration - so we measure multiple iterations in a loop and get the time for these
                    // the mean time is this total time / iterations

                    // for really small operations, like a single contains on a hashet that has 8 items you would probably want to call at least a feww hundred Contains
                    // and then average that - the maxN wouldn't work too well if that was just 8

                    startTicks = Stopwatch.GetTimestamp();

                    for (int i = 0; i < maxN; i++)
                    {
                        set.Contains(c[i]);
                    }

                    endTicks = Stopwatch.GetTimestamp();

                    ticks = ((endTicks - startTicks) * n) / (double)maxN;
                }
                else
                {
                    iterations = 1;

                    startTicks = Stopwatch.GetTimestamp();
                    for (int i = 0; i < n; i++)                     // loop overhead is ok because we assume there will be some loop in real-world scenario
                    {
                        set.Contains(c[i]);
                    }
                    endTicks = Stopwatch.GetTimestamp();

                    ticks = (double)(endTicks - startTicks);
                }

                double nanoSecs = PerfUtil.GetNanoSecondsFromTicks(ticks, Stopwatch.Frequency) - overheadNanoSecs;

                PerfDb.InsertMeasurement(dbConnStr, runID, benchmarkMethodID, n, iterations, nanoSecs, startTime, DateTime.Now);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                if (!string.IsNullOrEmpty(dbConnStr))
                {
                    // write error to db
                    PerfDb.InsertRunError(dbConnStr, runID, benchmarkMethodID, ex);
                }
                else
                {
                    // log error to file
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // cmd line params variables
            string dbConnStr         = null;
            int    runID             = 0;
            int    benchmarkMethodID = 0;
            int    n;
            int    maxN;

            try
            {
                DateTime startTime = DateTime.Now;
                //Console.WriteLine($"Args Count:" + args.Length.ToString());
                //foreach (string s in args)
                //{
                //	Console.WriteLine(s);
                //}
                //Console.ReadKey();

                string errMsg = PerfUtil.GetCmdLineParams_DbNAndMaxN(args, out dbConnStr, out runID, out benchmarkMethodID, out n, out maxN);
                //if (errMsg != null)
                //{
                //	Console.WriteLine(errMsg);
                //}
                //Console.WriteLine($"Args: {dbConnStr}; {runID.ToString()}; {benchmarkMethodID.ToString()}; {n.ToString()}; {maxN.ToString()}");
                //Console.ReadKey();

                int[] a  = new int[n];
                int[] a2 = new int[n];

                Random rand = new Random(89);
                for (int i = 0; i < a.Length; i++)
                {
                    a[i]  = rand.Next();
                    a2[i] = rand.Next();
                }

                FastHashSet <SmallStruct> setWarmup = new FastHashSet <SmallStruct>();
                setWarmup.Add(new SmallStruct(1, 2));

                FastHashSet <SmallStruct> set = new FastHashSet <SmallStruct>();

                double overheadNanoSecs = PerfUtil.GetTimestampOverheadInNanoSeconds();

                PerfUtil.DoGCCollect();

                int    iterations = 1;
                long   startTicks;
                long   endTicks;
                double ticks;

                // this is enough to jit things and not put everything in the cache
                //bool isContained = set.Contains(0);

                iterations = 1;

                startTicks = Stopwatch.GetTimestamp();
                for (int i = 0; i < a.Length; i++)
                {
                    set.Add(new SmallStruct(a[i], a2[i]));
                }

                endTicks = Stopwatch.GetTimestamp();

                ticks = (double)(endTicks - startTicks);

                double nanoSecs = PerfUtil.GetNanoSecondsFromTicks(ticks, Stopwatch.Frequency) - overheadNanoSecs;

                PerfDb.InsertMeasurement(dbConnStr, runID, benchmarkMethodID, n, iterations, nanoSecs, startTime, DateTime.Now);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                if (!string.IsNullOrEmpty(dbConnStr))
                {
                    // write error to db
                    PerfDb.InsertRunError(dbConnStr, runID, benchmarkMethodID, ex);
                }
                else
                {
                    // log error to file
                }
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            try
            {
                DateTime startTime = DateTime.Now;

                // first arg is job name, 2nd is params
                string jobName   = "";
                string paramsStr = "";
                if (args.Length > 0)
                {
                    jobName   = args[0].Trim();
                    paramsStr = args[1].Trim();
                }
                else
                {
                    //??? output error and exit
                }

                // 3rd arg is connection string override
                string dbConnStr;
                if (args.Length > 2)
                {
                    dbConnStr = args[2].Trim();
                }
                else
                {
                    dbConnStr = PerfRunner.Properties.Settings.Default.ConnStr.Trim();
                }

                JobWithBenchmarks j = PerfDb.ReadJobBenchmarkFromDb(dbConnStr, jobName, paramsStr);

                if (j.BenchmarkList != null && j.BenchmarkList.Count > 0)
                {
                    int totalRunCount = 0;
                    for (int i = 0; i < j.BenchmarkList.Count; i++)
                    {
                        int cnt = j.RunCount * j.BenchmarkList[i].CountN;
                        totalRunCount += cnt;
                    }

                    OrderAndIndex[] runOrderArray = new OrderAndIndex[totalRunCount];

                    Random rand = new Random(89);

                    int n = 0;
                    for (int i = 0; i < j.BenchmarkList.Count; i++)
                    {
                        int cnt  = j.RunCount;
                        int minN = j.BenchmarkList[i].MinN;
                        int maxN = j.BenchmarkList[i].MaxN;
                        int byN  = j.BenchmarkList[i].ByN;

                        for (int k = 0; k < cnt; k++)
                        {
                            for (int N = minN; N <= maxN; N += byN)
                            {
                                runOrderArray[n++] = new OrderAndIndex(rand.Next(int.MinValue, int.MaxValue), i, N);
                            }
                        }
                    }
                    Array.Sort(runOrderArray, new CompareOrderAndIndex());

                    EnvironmentInfo environInfo  = PerfUtil.GetEnvironmentInfo();
                    int             runID        = PerfDb.InsertRun(dbConnStr, j.JobID, j.Params, j.JobName, j.JobDescription, "", environInfo);
                    int             everyTenth   = runOrderArray.Length / 10;
                    int             nextTenth    = everyTenth;
                    int             nextPct      = 10;
                    DateTime        runStartTime = DateTime.Now;
                    Console.WriteLine("Starting Job: " + jobName + ", with Params: " + paramsStr + ", at: " + runStartTime.ToString("h:mm.s tt"));
                    for (int i = 0; i < runOrderArray.Length; i++)
                    {
                        BenchmarkMethod b = j.BenchmarkList[runOrderArray[i].index];
                        PerfUtil.StartProgramWithArguments_DbNAndMaxN(b.ExecutableFileName, dbConnStr, runID, b.BenchmarkMethodID, runOrderArray[i].n, b.MaxN);
                        if (i == nextTenth)
                        {
                            DateTime timeNow = DateTime.Now;
                            TimeSpan ts      = timeNow - runStartTime;
                            Console.WriteLine("Percent Done: " + nextPct.ToString("N0") + "%, Total Minutes So Far = " + ts.TotalMinutes.ToString("N2"));
                            nextTenth += everyTenth;
                            nextPct   += 10;
                        }
                    }
                    DateTime timeNowDone = DateTime.Now;
                    TimeSpan tsDone      = timeNowDone - runStartTime;
                    Console.WriteLine("Finished: Total Minutes = " + tsDone.TotalMinutes.ToString("N2"));
                }
            }
            catch (Exception ex)
            {
                PerfUtil.OutputError(ex);
                Console.ReadKey();
            }
        }