Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was looking for something very similar to what you described. I couldn't find such a framework, so I rolled my own. I should note that this is <strong>very simple</strong>, but sometimes simple is good!</p> <p>I would describe it as benchmarking meets unit testing. The concept is to isolate sections of code in order to measure or compare speed.</p> <p>A typical example of the attribute usage would look as follows:</p> <pre><code>[ProfileClass] public class ForEachLoopBenchmarks { [ProfileMethod] public void ForLoopBenchmark() { List&lt;int&gt; list = GetNumberList(); for (int i = 0; i &lt; list.Count; i++) { } } [ProfileMethod] public void ForEachLoopBenchmark() { List&lt;int&gt; list = GetNumberList(); foreach (int i in list) { } } private List&lt;int&gt; GetNumberList() { List&lt;int&gt; list = new List&lt;int&gt;(); for (int i = 0; i &lt; 1000; i++) { list.Add(i); } return list; } } </code></pre> <p>You then create a console app and paste the below code into the <em>Main</em> method and add a reference to the assembly that contains the previously described class that is decorated with the attributes. The execution time for each method (run 1000 times) will then be output to the console.</p> <pre><code>class Program { static void Main(string[] args) { ProfileRunner rp = new ProfileRunner(); rp.Run(); } } </code></pre> <p>The console output would look as follows:</p> <p><img src="https://i.stack.imgur.com/0KaYc.jpg" alt="console output"></p> <p>You need to add reference of the <em>pUnit.dll</em> to the console application and the class library that contains the methods marked with the attributes.</p> <p>You can get this as a Package from <strong>Nuget</strong> <a href="http://nuget.org/packages/punit/1.0.0" rel="nofollow noreferrer">here</a>.</p> <p><strong>Nuget Command:</strong> PM> Install-Package pUnit</p> <p>If you would rather the full source code, you can find it on <strong>Github</strong> <a href="https://github.com/bbraithwaite/pUnit" rel="nofollow noreferrer">here</a>.</p> <p>I based the method that actually measures the execution time on this question: <a href="https://stackoverflow.com/a/1048708/1139752">https://stackoverflow.com/a/1048708/1139752</a></p> <p>I cover the implementation in more detail in the following <a href="http://ideplorable.blogspot.com/2012/02/benchmarking-methods-in-c-made-easier.html" rel="nofollow noreferrer">blog post</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload