Last active
August 29, 2015 14:10
Revisions
-
alexandrnikitin renamed this gist
Feb 4, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
alexandrnikitin revised this gist
Nov 30, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,6 +43,10 @@ namespace PerformanceProblem for (var i = 0; i < 8000000; i++) { if (_list.Any()) // or if (_list.Count() > 0) // or if (_list.FirstOrDefault() != null) // or if (_list.SingleOrDefault() != null) // or other IEnumerable<T> method { return; } -
alexandrnikitin revised this gist
Nov 28, 2014 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,10 @@ namespace PerformanceProblem { for (var i = 0; i < 8000000; i++) { if (_list.Any()) { return; } } } } -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 10 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,30 +9,33 @@ namespace PerformanceProblem { public static void Main() { Measure(new DerivedClass()); Measure(new BaseClass<object>()); } private static void Measure(BaseClass<object> baseClass) { var sw = Stopwatch.StartNew(); baseClass.Run(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); } } public class DerivedClass : BaseClass<object> { } public class BaseClass<T> { private List<T> _list = new List<T>(); public BaseClass() { Enumerable.Empty<T>(); // or Enumerable.Repeat(new T(), 10); // or even new T(); // or foreach (var item in _list) {} } public void Run() -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,10 +39,7 @@ namespace PerformanceProblem { for (var i = 0; i < 8000000; i++) { _list.Any(); } } } -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,10 +22,6 @@ namespace PerformanceProblem } } public class StringClass : ClassBase<string> { } @@ -36,7 +32,7 @@ namespace PerformanceProblem public ClassBase() { Enumerable.Empty<T>(); } public void Run() -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,6 @@ namespace PerformanceProblem public class ClassBase<T> { private List<T> _list = new List<T>(); public ClassBase() { -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,9 +37,7 @@ namespace PerformanceProblem public ClassBase() { Enumerable.Empty<Node<T>>(); } public void Run() -
alexandrnikitin revised this gist
Nov 27, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,6 @@ namespace PerformanceProblem public class Node<T> { } public class StringClass : ClassBase<string> @@ -33,7 +32,8 @@ namespace PerformanceProblem public class ClassBase<T> { private List<T> _list = new List<T>(); private Node<T> _node = new Node<T>(); public ClassBase() { @@ -46,7 +46,7 @@ namespace PerformanceProblem { for (var i = 0; i < 8000000; i++) { if (_list.Any()) { return; } -
alexandrnikitin created this gist
Nov 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace PerformanceProblem { public class Program { public static void Main() { Measure(new StringClass()); Measure(new ClassBase<string>()); } private static void Measure(ClassBase<string> classBase) { var sw = Stopwatch.StartNew(); classBase.Run(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); } } public class Node<T> { public List<T> List = new List<T>(); } public class StringClass : ClassBase<string> { } public class ClassBase<T> { public Node<T> Node = new Node<T>(); public ClassBase() { foreach (var node in Enumerable.Empty<Node<T>>()) { } } public void Run() { for (var i = 0; i < 8000000; i++) { if (Node.List.Any()) { return; } } } } }