📜 ⬆️ ⬇️

Debriefing C # perfomance

I recently published a topic about nonsense code written by a Hindu. As a result, comments have been expressed that this is not at all nonsense, but a normal code in the C-style.

Yes, I will not argue - this is C-style, but I was curious - but what about the performance, which is faster? For "Practice without theory is blind, and theory without practice is dead." So in the morning I decided to make a little testik.
Wrote the following class:
class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  1. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  2. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  3. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  4. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  5. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  6. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  7. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  8. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  9. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  10. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  11. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  12. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  13. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  14. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  15. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  16. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  17. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  18. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  19. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  20. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  21. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  22. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  23. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  24. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  25. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  26. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  27. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  28. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  29. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  30. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  31. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  32. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  33. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  34. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  35. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  36. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  37. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  38. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  39. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  40. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  41. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  42. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  43. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  44. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  45. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  46. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
  47. class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .
class TestClass { private List < String > _generatedDigits; public TestClass() { _generatedDigits = new List < string >(); } public void GenerateList( Int32 listLength) { Random rnd = new Random ( DateTime .Now.Millisecond); _generatedDigits.Clear(); for ( Int32 i = 0; i < listLength; ++i) { _generatedDigits.Add(rnd.Next().ToString()); } } public bool TestTryParse() { bool result = true ; Int32 outValue = 0; foreach ( String str in _generatedDigits) { result &= Int32 .TryParse(str, out outValue); } return (result); } public bool TestIndusCode() { bool result = true ; foreach ( String str in _generatedDigits) { for ( int i = 0; i < str.Length; i++) if ( char .IsDigit(str[i]) == false ) result = false ; } return (result); } public bool TestRegularExpression() { bool result = true ; foreach ( String str in _generatedDigits) { result &= Regex.IsMatch(str, @"^\d{0,}$" ); } return (result); } } * This source code was highlighted with Source Code Highlighter .


As you can see from the class, I decided to check, and what is faster:


I measured the speed of the code in the following way:
')
  1. TestClass testClass = new TestClass ();
  2. testClass.GenerateList (10,000,000);
  3. Console .WriteLine (Environment.TickCount);
  4. testClass.TestTryParse ();
  5. Console .WriteLine (Environment.TickCount);
  6. testClass.TestIndusCode ();
  7. Console .WriteLine (Environment.TickCount);
  8. testClass.TestRegularExpression ();
  9. Console .WriteLine (Environment.TickCount);
* This source code was highlighted with Source Code Highlighter .


Well, it turned out as a result of me.
C-styleTryParseRegular expressionThe number of processed items
tenOsixteen10,000
1532203100,000
12531216561,000,000


And for greater visibility, let's build a graph.


Well, I confess, a little hurried to call it codebred, the truth triumphed :)
Thanks to habroles Egiptyanin beeruser lam0x86 porchini for discussing the previous topic :).

Source: https://habr.com/ru/post/47228/


All Articles