<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: performance testing code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 28 Aug 2008 18:01:14 GMT</pubDate>
    <description>DZone Snippets: performance testing code</description>
    <item>
      <title>Code execution timer</title>
      <link>http://snippets.dzone.com/posts/show/4254</link>
      <description>These two bits of code can be used to record &amp; output the execution time of a piece of code in microseconds.  NOTE: The functions used here are only available on BSD-like systems (I think).&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/* Put this line at the top of the file: */&lt;br /&gt;#include &lt;sys/time.h&gt;&lt;br /&gt;&lt;br /&gt;/* Put this right before the code you want to time: */&lt;br /&gt;struct timeval timer_start, timer_end;&lt;br /&gt;gettimeofday(&amp;timer_start, NULL);&lt;br /&gt;&lt;br /&gt;/* Put this right after the code you want to time: */&lt;br /&gt;gettimeofday(&amp;timer_end, NULL);&lt;br /&gt;double timer_spent = timer_end.tv_sec - timer_start.tv_sec + (timer_end.tv_usec - timer_start.tv_usec) / 1000000.0;&lt;br /&gt;printf("Time spent: %.6f\n", timer_spent);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Jul 2007 03:27:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4254</guid>
      <author>Minimiscience (Guildorn Tanaleth)</author>
    </item>
  </channel>
</rss>
