Popular recipes tagged "benchmark"http://code.activestate.com/recipes/tags/benchmark/popular/2011-12-25T23:41:23-08:00ActiveState Code RecipesBenchmark code with the with statement (Python)
2011-10-08T09:53:06-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577896-benchmark-code-with-the-with-statement/
<p style="color: grey">
Python
recipe 577896
by <a href="/recipes/users/4172944/">Steven D'Aprano</a>
(<a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/speed/">speed</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/timer/">timer</a>).
</p>
<p>Inspired by <a href="http://preshing.com/20110924/timing-your-code-using-pythons-with-statement">this post</a> I wrote this context manager to benchmark code blocks or function calls.</p>
<p>Usage is incredibly simple:</p>
<pre class="prettyprint"><code>with Timer():
... # code to benchmark goes here
</code></pre>
<p>The time taken (in seconds) will be printed when the code block completes. To capture the time taken programmatically is almost as easy:</p>
<pre class="prettyprint"><code>t = Timer()
with t:
... # code to benchmark goes here
time_taken = t.interval
</code></pre>
<p>Due to the difficulties of timing small snippets of code <em>accurately</em>, you should only use this for timing code blocks or function calls which take a significant amount of time to process. For micro-benchmarks, you should use the <code>timeit</code> module.</p>
Benchmark code with the with statement (Python)
2011-10-10T04:30:11-07:00vleonhttp://code.activestate.com/recipes/users/4179537/http://code.activestate.com/recipes/577900-benchmark-code-with-the-with-statement/
<p style="color: grey">
Python
recipe 577900
by <a href="/recipes/users/4179537/">vleon</a>
(<a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/speed/">speed</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/timer/">timer</a>).
</p>
<p>Inspired by <a href="http://preshing.com/20110924/timing-your-code-using-pythons-with-statement">this post</a> I wrote this context manager to benchmark code blocks or function calls.</p>
<p>Usage is incredibly simple:</p>
<pre class="prettyprint"><code>with Timer():
... # code to benchmark goes here
</code></pre>
<p>The time taken (in seconds) will be printed when the code block completes. To capture the time taken programmatically is almost as easy:</p>
<pre class="prettyprint"><code>t = Timer()
with t:
... # code to benchmark goes here
time_taken = t.interval
</code></pre>
<p>Due to the difficulties of timing small snippets of code <em>accurately</em>, you should only use this for timing code blocks or function calls which take a significant amount of time to process. For micro-benchmarks, you should use the <code>timeit</code> module.</p>
Compare algorithms for heapq.smallest (Python)
2011-12-25T23:41:23-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577573-compare-algorithms-for-heapqsmallest/
<p style="color: grey">
Python
recipe 577573
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/heaps/">heaps</a>, <a href="/recipes/tags/performance/">performance</a>).
Revision 3.
</p>
<p>General purpose technique for counting comparisons in various searching and sorting applications.</p>
A simple function benchmarking module (Python)
2010-08-27T09:26:48-07:00Timothee Cezardhttp://code.activestate.com/recipes/users/4174785/http://code.activestate.com/recipes/577377-a-simple-function-benchmarking-module/
<p style="color: grey">
Python
recipe 577377
by <a href="/recipes/users/4174785/">Timothee Cezard</a>
(<a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/function/">function</a>).
</p>
<p>This module enable its user to monitor the amount of time spend in between two commands start and stop.
The module is fairly imprecise if the monitored task is quick as the start and stop commands are fairly slow (2e-07 - 5e-07 second)</p>