Most viewed recipes tagged "timer"http://code.activestate.com/recipes/tags/timer/views/2012-12-06T03:24:35-08:00ActiveState Code RecipesResettable Timer class (a little enhancement from python builtin Timer class) (Python) 2010-09-24T08:37:58-07:00Eddy Jacobhttp://code.activestate.com/recipes/users/4175057/http://code.activestate.com/recipes/577407-resettable-timer-class-a-little-enhancement-from-p/ <p style="color: grey"> Python recipe 577407 by <a href="/recipes/users/4175057/">Eddy Jacob</a> (<a href="/recipes/tags/reset/">reset</a>, <a href="/recipes/tags/resettable/">resettable</a>, <a href="/recipes/tags/timer/">timer</a>). </p> <p>A more simple resettable timer class, by adding few logic from python builtin Timer code. the print statement in each function call is for debugging purposes only, to show if it works.</p> Pomodoro timer (Python) 2010-08-14T11:48:18-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577358-pomodoro-timer/ <p style="color: grey"> Python recipe 577358 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/gtd/">gtd</a>, <a href="/recipes/tags/pomodoro/">pomodoro</a>, <a href="/recipes/tags/timer/">timer</a>). </p> <p>A simple script that works as a pomodoro timer. Useful to enhance ones focus while working on something. The Pomodoro technique is described at <a href="http://www.pomodorotechnique.com/" rel="nofollow">http://www.pomodorotechnique.com/</a></p> <p>This script is an offline version of <a href="http://www.focusboosterapp.com/live.cfm" rel="nofollow">http://www.focusboosterapp.com/live.cfm</a></p> <p>It requires the <a href="http://www.mpg123.de/">Mpg123</a> program to play the audio and I obtained the ticking sounds from <a href="http://www.soundjay.com/clock-sounds-1.html" rel="nofollow">http://www.soundjay.com/clock-sounds-1.html</a></p> Benchmark 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> Countdown Timer (Python) 2012-12-06T03:24:35-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578363-countdown-timer/ <p style="color: grey"> Python recipe 578363 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/timer/">timer</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Ever wanted to set a timer that went off after a specified number of hours / minutes / seconds? This Windows recipe runs on the command line and does that with the arguments it accepts. Simple but effective, the program works well for remembering food in the oven among other things.</p> PythonTimer (Python) 2011-04-11T19:53:17-07:00Narendra Sisodiyahttp://code.activestate.com/recipes/users/4177605/http://code.activestate.com/recipes/577646-pythontimer/ <p style="color: grey"> Python recipe 577646 by <a href="/recipes/users/4177605/">Narendra Sisodiya</a> (<a href="/recipes/tags/timer/">timer</a>). Revision 2. </p> <p>import PythonTimer</p> <p>t = PythonTimer.TickTockTimer()</p> <p>t.StartTimer()</p> <p>t.GetTime()</p> <p>3.9744668006896973</p> <p>t.Pause()</p> <p>t.UnPause()</p> Interval Execute a function (Python) 2009-04-24T08:58:27-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576726-interval-execute-a-function/ <p style="color: grey"> Python recipe 576726 by <a href="/recipes/users/4168519/">Shao-chuan Wang</a> (<a href="/recipes/tags/thread/">thread</a>, <a href="/recipes/tags/timer/">timer</a>). Revision 4. </p> <p>Here I just want to keep it simple. If you want to execute a function every n second, this function should be competent. However, please note that the task is actually executed in another thread. </p> Simple MultiThreaded Timer Job Controller (Python) 2009-05-11T02:05:16-07:00sumerchttp://code.activestate.com/recipes/users/4170198/http://code.activestate.com/recipes/576748-simple-multithreaded-timer-job-controller/ <p style="color: grey"> Python recipe 576748 by <a href="/recipes/users/4170198/">sumerc</a> (<a href="/recipes/tags/job/">job</a>, <a href="/recipes/tags/multithread/">multithread</a>, <a href="/recipes/tags/task/">task</a>, <a href="/recipes/tags/timer/">timer</a>). Revision 2. </p> <p>We have tried to write an audit for our server to check our server's connection, status and other internal info and there are multiple threads invoking multiple tasks. So I came up with this simple utility that takes a job and runs it in a specific interval.</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>