static void Main(string[] args) { PerfTest perf = new PerfTest(); int repeat = 1000; perf.Start(); XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource)); //XmlDocument doc = new XmlDocument(); //doc.Load("test/northwind.xml"); Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop()); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress"); Console.WriteLine("Regular selection, warming..."); SelectNodes(nav, repeat, perf, expr); Console.WriteLine("Regular selection, testing..."); SelectNodes(nav, repeat, perf, expr); perf.Start(); IndexingXPathNavigator inav = new IndexingXPathNavigator( doc.CreateNavigator()); Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop()); perf.Start(); inav.AddKey("orderKey", "OrderIDs/Item", "OrderID"); Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop()); XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress"); perf.Start(); inav.BuildIndexes(); Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop()); Console.WriteLine("Indexed selection, warming..."); SelectIndexedNodes(inav, repeat, perf, expr2); Console.WriteLine("Indexed selection, testing..."); SelectIndexedNodes(inav, repeat, perf, expr2); }
/// <summary> /// Helper method that performs an Add test using HashSet, List and Dictionary /// </summary> private static void DoAddTest <T>(int testNumber, string description, List <T> inputs) { var hashsetResult = PerfTest.DoTest( inputs, () => new HashSet <T>(), (hs, i) => hs.Add(i), NumberOfTestRuns); var listResult = PerfTest.DoTest( inputs, () => new List <T>(), (l, i) => l.Add(i), NumberOfTestRuns); var dictResult = PerfTest.DoTest( inputs, () => new Dictionary <T, T>(), (dict, i) => dict.Add(i, i), NumberOfTestRuns); var dictResult2 = PerfTest.DoTest( inputs, () => new Dictionary <T, T>(), (dict, i) => dict[i] = i, NumberOfTestRuns); Console.WriteLine(@" Test {0} ({1}) Result: ------------------------------------------------ HashSet.Add : {2} List.Add : {3} Dictionary.Add : {4} Dictionary[n] = n : {5} ------------------------------------------------", testNumber, description, hashsetResult, listResult, dictResult, dictResult2); }
/// <summary> /// Adds the elements of an array to the end of this PerfTestCollection. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the end of this PerfTestCollection. /// </param> public virtual void AddRange(PerfTest[] items) { foreach (PerfTest item in items) { this.List.Add(item); } }
private static void DoRemoveTest <T>( int testNumber, string description, List <T> inputs, List <T> targets) { var hashsetResult = PerfTest.DoTest( targets, () => new HashSet <T>(inputs), (hs, t) => hs.Remove(t), NumberOfTestRuns); var listResult = PerfTest.DoTest( targets, () => new List <T>(inputs), (l, t) => l.Remove(t), NumberOfTestRuns); var dictResult = PerfTest.DoTest( targets, () => inputs.ToDictionary(i => i, i => i), (dict, t) => dict.Remove(t), NumberOfTestRuns); Console.WriteLine(@" Test {0} ({1}) Result: ------------------------------------------------ HashSet.Remove : {2} List.Remove : {3} Dictionary.Remove : {4} ------------------------------------------------", testNumber, description, hashsetResult, listResult, dictResult); }
private int PerformentTest(string title, int load, PerfTest execute) { stopWatch.Reset(); stopWatch.Start(); execute(load); stopWatch.Stop(); /*int load_added = 0; * * if (stopWatch.ElapsedMilliseconds < (TEST_MIN_DURATION)) * { * double dur_added = TEST_DURATION - stopWatch.ElapsedMilliseconds; * load_added = (int)(load * (dur_added / stopWatch.ElapsedMilliseconds)); * } * * if (load_added > 0) * { * stopWatch.Start(); * execute(load_added); * stopWatch.Stop(); * } * * int cps = CPS(load + load_added, stopWatch.ElapsedMilliseconds);*/ int cps = CPS(load, stopWatch.ElapsedMilliseconds); if (title != null) { string log = title + cps + ", elapsed :" + stopWatch.ElapsedMilliseconds; Debug.Log(log); sw.WriteLine(log); } return(cps); }
public static void HandlePerfArgs(List <string> args) { List <string> newArgs = new List <string>(); List <string> perfArgs = new List <string>(); Stack <string> argStack = new Stack <string>(Enumerable.Reverse(args)); bool needsOutputDir = true; bool specifiedPerfCollect = false; while (argStack.Any()) { string arg = argStack.Pop(); if (arg.StartsWith("--perf:", StringComparison.OrdinalIgnoreCase) && argStack.Any()) { if (arg.Equals("--perf:iterations", StringComparison.OrdinalIgnoreCase)) { PerfTest.DefaultIterations = int.Parse(argStack.Pop()); } else { if (arg.Equals("--perf:outputdir", StringComparison.OrdinalIgnoreCase)) { needsOutputDir = false; } else if (arg.Equals("--perf:collect", StringComparison.OrdinalIgnoreCase)) { specifiedPerfCollect = true; } perfArgs.Add(arg); perfArgs.Add(argStack.Pop()); } } else { newArgs.Add(arg); } } if (needsOutputDir) { perfArgs.Add("--perf:outputdir"); perfArgs.Add(Path.Combine(TestContext.Current.TestExecutionDirectory, "PerfResults")); } if (!specifiedPerfCollect) { // By default, just collect "stopwatch", in order to avoid (large) .etl files from being created // Other collect options include: BranchMispredictions+CacheMisses+InstructionRetired perfArgs.Add("--perf:collect"); perfArgs.Add("stopwatch"); } PerfTest.InitializeHarness(perfArgs.ToArray()); args.Clear(); args.AddRange(newArgs); }
static void Main(string[] args) { if (args == null || !args.Any()) { ShowHelp(); return; } try { Options.Parse(args); } catch (OptionException e) { System.Console.WriteLine($"Error during parsing input arguments: {e.ToString()}"); ShowHelp(); return; } try { if (_runPerformanceTest) { var pt = new PerfTest(); pt.RunMemoryTest(); System.Console.WriteLine(); pt.RunFileSystemTest(); } if (_generateFile) { System.Console.WriteLine(); new TestFileGenerator().GenerateInputFile(_testFileSize); } if (_runSorting) { System.Console.WriteLine(); new SortingManager(_sortingFilePath, GetOutputFileName(_sortingFilePath)).ProcessFile(); } if (_runCheck) { System.Console.WriteLine(); new SortOrderChecher(_checkingFilePath).CheckSortingOrder(); } } catch (Exception e) { System.Console.WriteLine($"Error during execution: {e.ToString()}"); return; } if (_showHelp) { ShowHelp(); } }
private void StartAddRemoveCB() { int LOOP_TIMES = 200000; Debug.Log("lua add & remove callback : "); sw.WriteLine("lua add & remove call back : "); PerfTest func = luaenv.Global.Get <PerfTest> ("LuaAddRemoveCB"); PerformentTest("lua add & remove callback : ", LOOP_TIMES, func); }
private static void SelectIndexedNodes(XPathNavigator nav, int repeat, PerfTest perf, XPathExpression expr) { int counter = 0; perf.Start(); for (int i=0; i<repeat; i++) { XPathNodeIterator ni = nav.Select(expr); while (ni.MoveNext()) counter++; } Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, perf.Stop(), counter); }
private void StartConstruct() { int LOOP_TIMES = 1000000; Debug.Log("lua call construct :"); sw.WriteLine("lua call construct :"); PerfTest func = luaenv.Global.Get <PerfTest> ("LuaConstructClass"); PerformentTest("lua construct class : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaConstructStruct"); PerformentTest("lua construct struct : ", LOOP_TIMES, func); }
private static void SelectIndexedNodes(XPathNavigator nav, int repeat, PerfTest perf, XPathExpression expr) { int counter = 0; perf.Start(); for (int i = 0; i < repeat; i++) { XPathNodeIterator ni = nav.Select(expr); while (ni.MoveNext()) { counter++; } } Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, perf.Stop(), counter); }
/// <summary> /// 性能测试 /// </summary> /// <returns></returns> public static void UnitTest_Performance() { Console.WriteLine("UnitTest_Performance"); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int cnt = 0; for (int i = 0; i < 500000; i++) { cnt += i; } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); sw.Reset(); sw.Start(); cnt = foo(); sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); sw.Reset(); sw.Start(); cnt = 0; for (int i = 0; i < 1000000; i++) { FuncCallResult(ref cnt, i); } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); PerfTest test = new PerfTest(); sw.Reset(); sw.Start(); cnt = 0; for (int i = 0; i < 1000000; i++) { test.FuncCallResult(ref cnt, i); } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); }
private void StartCSCallLuaCB() { int LOOP_TIMES = 1000000; Debug.Log("C# call lua callbak :"); sw.WriteLine("C# call lua callbak :"); PerfTest func = luaenv.Global.Get <PerfTest> ("LuaBaseParaCB"); PerformentTest("invoke base param callback : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaClassParaCB"); PerformentTest("invoke class param callback : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaStructParaCB"); PerformentTest("invoke struct param callback : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaVec3ParaCB"); PerformentTest("invoke vector3 param callback : ", LOOP_TIMES, func); }
static void Main(string[] args) { PerfTest test = new PerfTest(); test.init(); Stopwatch sw = Stopwatch.StartNew(); for (int x = 0; x < 100; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { PointD pt = new PointD() { X = x, Y = y, Z = z }; test.checkPointIndexOf(pt); } } } sw.Stop(); Console.WriteLine(sw.Elapsed); sw = Stopwatch.StartNew(); for (int x = 0; x < 100; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { PointD pt = new PointD() { X = x, Y = y, Z = z }; test.checkPointForBreak(pt); } } } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public async override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. await Task.Delay(100); var sw = new Stopwatch(); const int runs = 10; long totalCompileTime = 0; long totalReflectionTime = 0; for (int i = 0; i < runs + 1; i++) { sw.Restart(); PerfTest.TestCompile(); sw.Stop(); if (i != 0) { totalCompileTime += sw.ElapsedMilliseconds; } sw.Restart(); PerfTest.TestReflection(); sw.Stop(); if (i != 0) { totalReflectionTime += sw.ElapsedMilliseconds; } } Console.WriteLine(UIDevice.CurrentDevice.Model); var expressionCount = PerfTest.TestRounds * PerfTest.TestExpressions.Count; Console.WriteLine("Compile took {0}ms per {1} expressions", totalCompileTime / runs, expressionCount); Console.WriteLine("Reflection took {0}ms per {1} expressions", totalReflectionTime / runs, expressionCount); }
static void Main(string[] args) { PerfTest perf = new PerfTest(); int repeat = 1000; perf.Start(); XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource)); //XmlDocument doc = new XmlDocument(); //doc.Load("test/northwind.xml"); Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop()); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress"); Console.WriteLine("Regular selection, warming..."); SelectNodes(nav, repeat, perf, expr); Console.WriteLine("Regular selection, testing..."); SelectNodes(nav, repeat, perf, expr); perf.Start(); IndexingXPathNavigator inav = new IndexingXPathNavigator( doc.CreateNavigator()); Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop()); perf.Start(); inav.AddKey("orderKey", "OrderIDs/Item", "OrderID"); Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop()); XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress"); perf.Start(); inav.BuildIndexes(); Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop()); Console.WriteLine("Indexed selection, warming..."); SelectIndexedNodes(inav, repeat, perf, expr2); Console.WriteLine("Indexed selection, testing..."); SelectIndexedNodes(inav, repeat, perf, expr2); }
public void FullDocValidation() { XmlDocument doc = new XmlDocument(); doc.Load(Globals.GetResource(Globals.PubsNsResource)); XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.PubsNsResource)); XmlSchema xsd = XmlSchema.Read( Globals.GetResource(Globals.PubsNsSchemaResource), null); xsd.Compile(null); // Warmup XmlReader r = new XmlValidatingReader( new XmlTextReader(new StringReader(doc.OuterXml))); while (r.Read()) { } r = new XmlValidatingReader( new XPathNavigatorReader(doc.CreateNavigator())); while (r.Read()) { } r = new XmlValidatingReader( new XPathNavigatorReader(xdoc.CreateNavigator())); while (r.Read()) { } PerfTest pt = new PerfTest(); int count = 10; float xml = 0; float xpath = 0; float xdoctime = 0; for (int i = 0; i < count; i++) { pt.Start(); r = new XmlValidatingReader( new XmlTextReader(new StringReader(doc.OuterXml))); while (r.Read()) { } xml += pt.Stop(); pt.Start(); r = new XmlValidatingReader( new XPathNavigatorReader(doc.CreateNavigator())); while (r.Read()) { } xpath += pt.Stop(); pt.Start(); r = new XmlValidatingReader( new XPathNavigatorReader(xdoc.CreateNavigator())); while (r.Read()) { } xdoctime += pt.Stop(); } Console.WriteLine("OuterXml validation: {0}", xml / count); Console.WriteLine("XPathNavigatorReader validation: {0}", xpath / count); Console.WriteLine("XPathDocument/Reader validation: {0}", xdoctime / count); }
public void SubtreeSpeed() { XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.LibraryResource)); XPathNavigator nav = xdoc.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.Load(Globals.GetResource(Globals.LibraryResource)); XslTransform xslt = new XslTransform(); xslt.Load(new XmlTextReader( Globals.GetResource(this.GetType().Namespace + ".print_root.xsl"))); PerfTest pt = new PerfTest(); // Warmup MemoryStream stmdom = new MemoryStream(); XmlDocument wd = new XmlDocument(); wd.LoadXml(doc.DocumentElement.FirstChild.OuterXml); xslt.Transform(wd, null, stmdom, null); MemoryStream stmxpath = new MemoryStream(); nav.MoveToRoot(); nav.MoveToFirstChild(); nav.MoveToFirstChild(); xslt.Transform(new SubtreeeXPathNavigator(nav), null, stmxpath, null); nav = doc.CreateNavigator(); int count = 10; float dom = 0; float xpath = 0; for (int i = 0; i < count; i++) { GC.Collect(); System.Threading.Thread.Sleep(1000); stmdom = new MemoryStream(); pt.Start(); // Create a new document for each child foreach (XmlNode testNode in doc.DocumentElement.ChildNodes) { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(testNode.OuterXml); // Transform the subset. xslt.Transform(tmpDoc, null, stmdom, null); } dom += pt.Stop(); GC.Collect(); System.Threading.Thread.Sleep(1000); stmxpath = new MemoryStream(); XPathExpression expr = nav.Compile("/library/book"); pt.Start(); XPathNodeIterator books = nav.Select(expr); while (books.MoveNext()) { xslt.Transform(new SubtreeeXPathNavigator(books.Current), null, stmxpath, null); } xpath += pt.Stop(); } Console.WriteLine("XmlDocument transformation: {0}", dom / count); Console.WriteLine("SubtreeXPathNavigator transformation: {0}", xpath / count); stmdom.Position = 0; stmxpath.Position = 0; Console.WriteLine(new StreamReader(stmdom).ReadToEnd()); Console.WriteLine(new string('*', 100)); Console.WriteLine(new string('*', 100)); Console.WriteLine(new StreamReader(stmxpath).ReadToEnd()); }
public virtual void afterRun(PerfTest test, PerfTestRun run) { // nothing to do }
public void TrasformItems() { string xml = @"<library> <book genre='novel' ISBN='1-861001-57-5'> <title>Pride And Prejudice</title> </book> <book genre='novel' ISBN='1-81920-21-2'> <title>Hook</title> </book> </library>"; string xsl = @"<stylesheet version='1.0' xmlns='http://www.w3.org/1999/XSL/Transform' > <output method='text' /> <template match='/'> <variable name='first' select='/*[1]/*[1]' /> <variable name='second' select='/publishers/pub_id' /> <variable name='third' select='//*[title_id=""BU2075""]' /> </template> </stylesheet>"; XslTransform xslt = new XslTransform(); xslt.Load(new XmlTextReader(new StringReader(xsl)), null, this.GetType().Assembly.Evidence); XPathDocument wp = new XPathDocument(Globals.GetResource(Globals.PubsResource)); XmlDocument wd = new XmlDocument(); wd.Load(Globals.GetResource(Globals.PubsResource)); PerfTest p = new PerfTest(); p.Start(); // Load the entire doc. XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.PubsResource)); // Create a new document for each child XPathNodeIterator books = doc.CreateNavigator().Select("/dsPubs/publishers"); while (books.MoveNext()) { XPathDocument tmpDoc = new XPathDocument( new XPathNavigatorReader(books.Current)); // Pass the document containing the node fragment // to the Transform method. xslt.Transform(tmpDoc, null, Console.Out, null); } Console.WriteLine("\nElapsed: {0}", p.Stop()); p = new PerfTest(); p.Start(); // Load the entire doc. XmlDocument xdoc = new XmlDocument(); xdoc.Load(Globals.GetResource(Globals.PubsResource)); // Create a new document containing just the node fragment. // Create a new document for each child foreach (XmlNode testNode in xdoc.SelectNodes("/dsPubs/publishers")) { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(testNode.OuterXml); // Pass the document containing the node fragment // to the Transform method. xslt.Transform(tmpDoc, null, Console.Out, null); } Console.WriteLine("\nElapsed: {0}", p.Stop()); }
public void FullDocValidation() { XmlDocument doc = new XmlDocument(); doc.Load(Globals.GetResource(Globals.PubsNsResource)); XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.PubsNsResource)); XmlSchema xsd = XmlSchema.Read( Globals.GetResource(Globals.PubsNsSchemaResource), null); xsd.Compile(null); // Warmup XmlReader r = new XmlValidatingReader( new XmlTextReader(new StringReader(doc.OuterXml))); while (r.Read()) {} r = new XmlValidatingReader( new XPathNavigatorReader(doc.CreateNavigator())); while (r.Read()) {} r = new XmlValidatingReader( new XPathNavigatorReader(xdoc.CreateNavigator())); while (r.Read()) {} PerfTest pt = new PerfTest(); int count = 10; float xml = 0; float xpath = 0; float xdoctime = 0; for (int i = 0; i < count; i++) { pt.Start(); r = new XmlValidatingReader( new XmlTextReader(new StringReader(doc.OuterXml))); while (r.Read()) {} xml += pt.Stop(); pt.Start(); r = new XmlValidatingReader( new XPathNavigatorReader(doc.CreateNavigator())); while (r.Read()) {} xpath += pt.Stop(); pt.Start(); r = new XmlValidatingReader( new XPathNavigatorReader(xdoc.CreateNavigator())); while (r.Read()) {} xdoctime += pt.Stop(); } Console.WriteLine("OuterXml validation: {0}", xml / count); Console.WriteLine("XPathNavigatorReader validation: {0}", xpath / count); Console.WriteLine("XPathDocument/Reader validation: {0}", xdoctime / count); }
public virtual void beforeRun(PerfTest test, PerfTestRun run) { // nothing to do }
public static void Main(string[] args) { PerfTest.Run(); }
public void TrasformItems() { string xml = @"<library> <book genre='novel' ISBN='1-861001-57-5'> <title>Pride And Prejudice</title> </book> <book genre='novel' ISBN='1-81920-21-2'> <title>Hook</title> </book> </library>"; string xsl = @"<stylesheet version='1.0' xmlns='http://www.w3.org/1999/XSL/Transform' > <output method='text' /> <template match='/'> <variable name='first' select='/*[1]/*[1]' /> <variable name='second' select='/publishers/pub_id' /> <variable name='third' select='//*[title_id=""BU2075""]' /> </template> </stylesheet>"; XslTransform xslt = new XslTransform(); xslt.Load(new XmlTextReader(new StringReader(xsl)), null, this.GetType().Assembly.Evidence); XPathDocument wp = new XPathDocument(Globals.GetResource(Globals.PubsResource)); XmlDocument wd = new XmlDocument(); wd.Load(Globals.GetResource(Globals.PubsResource)); PerfTest p = new PerfTest(); p.Start(); // Load the entire doc. XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.PubsResource)); // Create a new document for each child XPathNodeIterator books = doc.CreateNavigator().Select("/dsPubs/publishers"); while (books.MoveNext()) { XPathDocument tmpDoc = new XPathDocument( new XPathNavigatorReader(books.Current)); // Pass the document containing the node fragment // to the Transform method. xslt.Transform(tmpDoc, null, Console.Out, null); } Console.WriteLine("\nElapsed: {0}", p.Stop()); p = new PerfTest(); p.Start(); // Load the entire doc. XmlDocument xdoc = new XmlDocument(); xdoc.Load(Globals.GetResource(Globals.PubsResource)); // Create a new document containing just the node fragment. // Create a new document for each child foreach (XmlNode testNode in xdoc.SelectNodes("/dsPubs/publishers")) { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(testNode.OuterXml); // Pass the document containing the node fragment // to the Transform method. xslt.Transform(tmpDoc, null, Console.Out, null); } Console.WriteLine("\nElapsed: {0}", p.Stop()); }
static partial void AfterTestRun() { PerfTest.DisposeHarness(); }
public static Result RunTest(string label, MakePerfTest createTest, int?requestedIterations, int multiplier) { const int DefaultIterations = 21; int iterations = requestedIterations.HasValue ? requestedIterations.Value : DefaultIterations; // warm-up if (iterations > 1) { PerfTest test = createTest(); test.UntimedPrepare(); test.TimedIteration(); if (iterations > 5) { test = createTest(); test.UntimedPrepare(); test.TimedIteration(); } } double[] elapsed = new double[iterations]; for (int i = 0; i < iterations; i++) { PerfTest test = createTest(); test.UntimedPrepare(); Stopwatch timer = Stopwatch.StartNew(); for (int j = 0; j < multiplier; j++) { test.TimedIteration(); } timer.Stop(); elapsed[i] = timer.ElapsedMilliseconds / 1000d; } Array.Sort(elapsed); double sum = 0; for (int i = 0; i < iterations; i++) { sum += elapsed[i]; } double average = sum / iterations; double variance = 0; double stability = 0; for (int i = 0; i < iterations; i++) { double deviation = elapsed[i] - average; variance += deviation * deviation; double sta = Math.Max(elapsed[i], average) / Math.Min(elapsed[i], average) - 1; stability += sta * sta; } variance /= iterations; stability = Math.Sqrt(stability / iterations); double median = ((iterations & 1) != 0) ? elapsed[iterations / 2] : (elapsed[(iterations - 1) / 2] + elapsed[(iterations - 1) / 2 + 1]) / 2; return(new Result { label = label, median = median, average = average, stability = stability, iterations = iterations, sum = sum, variance = variance, data = elapsed, }); }
/// <summary> /// Removes the first occurrence of a specific PerfTest from this PerfTestCollection. /// </summary> /// <param name="value"> /// The PerfTest value to remove from this PerfTestCollection. /// </param> public virtual void Remove(PerfTest value) { this.List.Remove(value); }
/// <summary> /// Initializes a new instance of the PerfTestCollection class, containing elements /// copied from an array. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the new PerfTestCollection. /// </param> public PerfTestCollection(PerfTest[] items) { this.AddRange(items); }
public void SubtreeSpeed() { XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.LibraryResource)); XPathNavigator nav = xdoc.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.Load(Globals.GetResource(Globals.LibraryResource)); XslTransform xslt = new XslTransform(); xslt.Load(new XmlTextReader( Globals.GetResource(this.GetType().Namespace + ".print_root.xsl"))); PerfTest pt = new PerfTest(); // Warmup MemoryStream stmdom = new MemoryStream(); XmlDocument wd = new XmlDocument(); wd.LoadXml(doc.DocumentElement.FirstChild.OuterXml); xslt.Transform(wd, null, stmdom, null); MemoryStream stmxpath = new MemoryStream(); nav.MoveToRoot(); nav.MoveToFirstChild(); nav.MoveToFirstChild(); xslt.Transform(new SubtreeeXPathNavigator(nav), null, stmxpath, null); nav = doc.CreateNavigator(); int count = 10; float dom = 0; float xpath = 0; for (int i = 0; i < count; i++) { GC.Collect(); System.Threading.Thread.Sleep(1000); stmdom = new MemoryStream(); pt.Start(); // Create a new document for each child foreach (XmlNode testNode in doc.DocumentElement.ChildNodes) { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(testNode.OuterXml); // Transform the subset. xslt.Transform(tmpDoc, null, stmdom, null); } dom += pt.Stop(); GC.Collect(); System.Threading.Thread.Sleep(1000); stmxpath = new MemoryStream(); XPathExpression expr = nav.Compile("/library/book"); pt.Start(); XPathNodeIterator books = nav.Select(expr); while (books.MoveNext()) { xslt.Transform(new SubtreeeXPathNavigator(books.Current), null, stmxpath, null); } xpath += pt.Stop(); } Console.WriteLine("XmlDocument transformation: {0}", dom / count); Console.WriteLine("SubtreeXPathNavigator transformation: {0}", xpath / count); stmdom.Position = 0; stmxpath.Position = 0; Console.WriteLine(new StreamReader(stmdom).ReadToEnd()); Console.WriteLine(new string('*', 100)); Console.WriteLine(new string('*', 100)); Console.WriteLine(new StreamReader(stmxpath).ReadToEnd()); }
private void StartLuaCallCS() { int LOOP_TIMES = 1000000; Debug.Log("lua call C# member : "); sw.WriteLine("lua call C# member : "); PerfTest func = luaenv.Global.Get <PerfTest> ("LuaAccessCSBaseMember_get"); PerformentTest("lua call C# member : base member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSBaseMember_set"); PerformentTest("lua call C# member : base member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSClassMember_get"); PerformentTest("lua call C# member : class member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSClassMember_set"); PerformentTest("lua call C# member : class member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessStructMember_get"); PerformentTest("lua call C# member : struct member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessStructMember_set"); PerformentTest("lua call C# member : struct member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessVec3Member_get"); PerformentTest("lua call C# member : vector3 member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessVec3Member_set"); PerformentTest("lua call C# member : vector3 member, set : ", LOOP_TIMES, func); Debug.Log("lua call C# member funtion : "); sw.WriteLine("lua call C# member funtion : "); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSBaseMemberFunc"); PerformentTest("lua call C# member funtion : base parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSClassMemberFunc"); PerformentTest("lua call C# member funtion : class parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStructMemberFunc"); PerformentTest("lua call C# member funtion : struct parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSVec3MemberFunc"); PerformentTest("lua call C# member funtion : vector3 parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSInMemberFunc"); PerformentTest("lua call C# member funtion : input parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSOutMemberFunc"); PerformentTest("lua call C# member funtion : output parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSInOutMemberFunc"); PerformentTest("lua call C# member funtion : in & output parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSTwoMemberFunc"); PerformentTest("lua call C# member funtion : two parameter member function : ", LOOP_TIMES, func); Debug.Log("lua call static memeber : "); sw.WriteLine("lua call static memeber :"); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticBaseMember_get"); PerformentTest("lua call C# static member : base member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSStaticBaseMember_set"); PerformentTest("lua call C# static member : base member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticClassMember_get"); PerformentTest("lua call C# static member : class member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSStaticClassMember_set"); PerformentTest("lua call C# static member : class member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticStructMember_get"); PerformentTest("lua call C# static member : struct member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSStaticStructMember_set"); PerformentTest("lua call C# static member : struct member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticVec3Member_get"); PerformentTest("lua call C# static member : vector3 member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSStaticVec3Member_set"); PerformentTest("lua call C# static member : vector3 member, set : ", LOOP_TIMES, func); Debug.Log("lua call C# static member funtion : "); sw.WriteLine("lua call C# member funtion : "); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticBaseMemberFunc"); PerformentTest("lua call C# static member funtion : base parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticClassMemberFunc"); PerformentTest("lua call C# static member funtion : class parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticStructMemberFunc"); PerformentTest("lua call C# static member funtion : struct parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticVec3MemberFunc"); PerformentTest("lua call C# static member funtion : vector3 parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticInMemberFunc"); PerformentTest("lua call C# static member funtion : input parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticOutMemberFunc"); PerformentTest("lua call C# static member funtion : output parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticInOutMemberFunc"); PerformentTest("lua call C# static member funtion : in & output parameter member function : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest> ("LuaAccessCSStaticTwoMemberFunc"); PerformentTest("lua call C# static member funtion : two parameter member function : ", LOOP_TIMES, func); Debug.Log("lua call C# array & num : "); sw.WriteLine("lua call C# array & enum : "); func = luaenv.Global.Get <PerfTest>("LuaAccessCSEnumFunc_get"); PerformentTest("lua call C# member : enum member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSEnumFunc_set"); PerformentTest("lua call C# member : enum member, set : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSArrayFunc_get"); PerformentTest("lua call C# member : array member, get : ", LOOP_TIMES, func); func = luaenv.Global.Get <PerfTest>("LuaAccessCSArrayFunc_set"); PerformentTest("lua call C# member : array member, set : ", LOOP_TIMES, func); }
/// <summary> /// Adds an instance of type PerfTest to the end of this PerfTestCollection. /// </summary> /// <param name="value"> /// The PerfTest to be added to the end of this PerfTestCollection. /// </param> public virtual void Add(PerfTest value) { this.List.Add(value); }
protected TestRun(int run, PerfTest perfTest, int availableCores) { _perfTest = perfTest; _availableCores = availableCores; RunIndex = run; }
public override void ViewDidLoad() { base.ViewDidLoad(); Task.Run(() => PerfTest.Run()); }
protected TestRun(int run, PerfTest perfTest, int availableCores) { _perfTest = perfTest; _availableCores = availableCores; RunIndex = run; }
/// <summary> /// Return the zero-based index of the first occurrence of a specific value /// in this PerfTestCollection /// </summary> /// <param name="value"> /// The PerfTest value to locate in the PerfTestCollection. /// </param> /// <returns> /// The zero-based index of the first occurrence of the _ELEMENT value if found; /// -1 otherwise. /// </returns> public virtual int IndexOf(PerfTest value) { return this.List.IndexOf(value); }
/// <summary> /// Determines whether a specfic PerfTest value is in this PerfTestCollection. /// </summary> /// <param name="value"> /// The PerfTest value to locate in this PerfTestCollection. /// </param> /// <returns> /// true if value is found in this PerfTestCollection; /// false otherwise. /// </returns> public virtual bool Contains(PerfTest value) { return this.List.Contains(value); }
/// <summary> /// Inserts an element into the PerfTestCollection at the specified index /// </summary> /// <param name="index"> /// The index at which the PerfTest is to be inserted. /// </param> /// <param name="value"> /// The PerfTest to insert. /// </param> public virtual void Insert(int index, PerfTest value) { this.List.Insert(index, value); }