title: Calculation of time execution as separate class, where function is variable
body: <p>Let be the following binary search function:</p>
  
  <pre><code>public static bool BinarySearching(int[] array, int searchValue)
  {
      Array.Sort(array);
      double p = 0;
      double q = 0;
      int r = array.Length - 1;
  
      while (p &lt;= r)
      {
          q = Math.Floor((p + r) / 2);
  
          if (array[(int)q] == searchValue)
          {
              return true;
          }
  
          else if (array[(int)q] != searchValue &amp;&amp; array[(int)q] &gt; searchValue)
          {
              r = (int)(q - 1);
          }
  
          else if (array[(int)q] != searchValue &amp;&amp; array[(int)q] &lt; searchValue)
          {
              p = (int)(q + 1);
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If we want to measure its execution time, we would do something like </p>
  
  <pre><code>var watch = System.Diagnostics.Stopwatch.StartNew();
  BinarySearching(int[] array, int searchValue);
  watch.Stop();
  var elapsedMs = watch.ElapsedMilliseconds;
  </code></pre>
  
  <p>But is it any more bautiful way to measure like through the separate function, such that varaible is calculated function itself? For example, in pseudocode it is </p>
  
  <pre><code>public static string ComplexityCounter(bool algorithm(int[] array, int searchValue))
  {
      var watch = System.Diagnostics.Stopwatch.StartNew();
      algorithm(int[] array, int searchValue);
      watch.Stop();
      var elapsedMs = watch.ElapsedMilliseconds;
      string result = elapsedMs.ToString();
      return result;
  }
  </code></pre>
  
  <p>And, sure it doesn't work in terms of C#, can you help me to revise it or to propose your own try ? The most interesting is to find such structure for all algorithms regardless of the type of variable it produces. </p>