Login
Два статических метода... или 4 строки LINQ?
515 просмотров
Перейти к просмотру всей ветки
Murr патриот
in Antwort dymanoid 20.03.19 23:36
Тест:
CodeNamespace codeNamespace;const Int32 TopLimit = 1000000;[TestMethod]public void TestMethod1(){Type[] types = typeof(System.Xml.Serialization.XmlAttributeAttribute).Assembly.GetTypes();Stopwatch stopwatch1 = new Stopwatch();stopwatch1.Restart();for (int i = 0; i < TopLimit; ++i){codeNamespace = new CodeNamespace();AddImports(codeNamespace, GetNamespacesForTypes(types));}stopwatch1.Stop();Debug.Print("Static methods : " + stopwatch1.ElapsedMilliseconds + " ms");Stopwatch stopwatch2 = new Stopwatch();stopwatch2.Restart();for (int i = 0; i < TopLimit; ++i){codeNamespace = new CodeNamespace();AddCodeNamespaces(types);}stopwatch2.Stop();Debug.Print("Using LINQ : " + stopwatch2.ElapsedMilliseconds + " ms");}
Static methods : 317983 ms
Using LINQ : 935715 ms
Надо посмотреть можно ли вынести компиляцию сборки из цикла...