示例#1
0
 void Add(EzDataPoint dp)
 {
     if (_where == null || _where(dp))
     {
         _graph.Add(dp);
     }
 }
示例#2
0
        public void Run(Benchmarker b, int listCount)
        {
            _count = listCount;

            int end = Console.CursorTop;

            b.RunPublicBenchmarks(this, false, () =>
            {
                int start = Console.CursorTop;
                b.PrintResults(Console.Out);
                end = Console.CursorTop;
                Console.CursorTop = start;

                // Send results to _graph
                if (_graph != null)
                {
                    foreach (var row in b.Results)
                    {
                        string rowName = row.Key;
                        var result     = row.Value;
                        var pair1      = rowName.SplitAt(": ");
                        var pair2      = pair1.B.SplitAt(": ");

                        var graphName = pair2.A.ToString();
                        if (graphName.StartsWith("Scan by") && graphName.EndsWith("x"))
                        {
                            // avoid creating separate graphs for "Scan by ... 1000x" and "Scan by ... 333x"
                            graphName = graphName.Left(graphName.LastIndexOf(' '));
                        }

                        var dp = new EzDataPoint {
                            Parameter = double.Parse(pair1.A.ToString()),
                            GraphId   = graphName,
                            Series    = pair2.B.ToString(),
                            Value     = result.Avg()
                        };
                        Add(dp);

                        // Make a second version of the dictionary graph without SortedList
                        if (dp.GraphId.ToString().StartsWith("Dictionary") && dp.Series != "SortedList")
                        {
                            dp         = dp.Clone();
                            dp.GraphId = dp.GraphId.ToString() + " (no SortedList)";
                            Add(dp);
                        }

                        // Make a second version of the "@ random indexes" graphs for small lists
                        if (dp.GraphId.ToString().Contains("random index") && (double)dp.Parameter < 10000)
                        {
                            dp         = dp.Clone();
                            dp.GraphId = dp.GraphId.ToString() + "\u200B";                             // zero-width space just to change the graph ID
                            Add(dp);
                        }
                    }
                }
            },
                                  string.Format("{0,8}: ", listCount), true);
            Console.CursorTop = end;
        }