szabototo89 / CodeSharper

Refactoring tool, written in C# and using TDD for developing
2 stars 0 forks source link

[idea] Code Performance Testing Library (CPTL) #26

Open szabototo89 opened 10 years ago

szabototo89 commented 10 years ago

CPTL should be a performance testing library in C#. It should run and measure the execution time of source code:

  [PerformanceTest]
  public void MeasureCodeTest() { 
     CodePerformance.Measure(() => {
          DoSomething1();
          // ...
          DoSomethingN();
     });
  }

The above code will compile to:

  [PerformanceTest]
  public void MeasureCodeTest() { 
     CodePerformance.Measure(() => {
          Time.Measure(() => DoSomething1()); // measures every statement in Measure method
          // ...
          Time.Measure(() => DoSomethingN());
     });
  }

Possible problems: Handle statements such as: branches, loops or declarations.

szabototo89 commented 10 years ago

However this solution would solve this problem:

  [PerformanceTest]
  public void MeasureCodeTest() { 
     CodePerformance.Measure(() => {
          Time.BeginMeasure("DoSomething1"); // start measuring of DoSomething1
          DoSomething1();
          Time.EndMeasure();
          // ...
          Time.BeginMeasure("DoSomethingN"); // start measuring of DoSomethingN
          DoSomethingN();
          Time.EndMeasure();
     });
  }