<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

      <title>Comments on: No time like the present</title>
      <link>http://ask.metafilter.com/85347/No-time-like-the-present/</link>
      <description>Comments on Ask MetaFilter post No time like the present</description>
	  	  <pubDate>Wed, 05 Mar 2008 00:44:32 -0800</pubDate>
      <lastBuildDate>Wed, 05 Mar 2008 00:44:32 -0800</lastBuildDate>
      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>

<item>
  	<title>Question: No time like the present</title>
  	<link>http://ask.metafilter.com/85347/No-time-like-the-present</link>	
  	<description>I&apos;m interested in aspects of benchmarking with the help of UNIX&apos;s &lt;code&gt;time&lt;/code&gt;, specifically, what &lt;code&gt;user&lt;/code&gt;, &lt;code&gt;system&lt;/code&gt; and &lt;code&gt;elapsed&lt;/code&gt; times correspond to, within the functional context of the system and the tested application. I have a very rough idea what the results of &lt;i&gt;time&lt;/i&gt; point to in terms of CPU contention, with respect to the result of &lt;code&gt;elapsed&lt;/code&gt; time, if &lt;code&gt;elapsed&lt;/code&gt; is greater than the sum of &lt;code&gt;user&lt;/code&gt; and &lt;code&gt;system&lt;/code&gt; times.&lt;br&gt;
&lt;br&gt;
&#8226; What does it mean that &lt;code&gt;user&lt;/code&gt; makes &lt;i&gt;non-system calls&lt;/i&gt; (what are those calls?)&lt;br&gt;
&lt;br&gt;
&#8226; Likewise, what does it mean specifically that &lt;code&gt;system&lt;/code&gt; makes &lt;i&gt;system calls&lt;/i&gt; (what are those calls?)&lt;br&gt;
&lt;br&gt;
Would I use &lt;code&gt;user&lt;/code&gt; and &lt;code&gt;system&lt;/code&gt; mean times to establish how to guide function profiling, within an application?&lt;br&gt;
&lt;br&gt;
&#8226; What benchmarking results should I use as criteria for comparing one test result with another, all else the same? &lt;br&gt;
&lt;br&gt;
For example, let&apos;s say I run &lt;code&gt;sed -e &apos;s/+/-/&apos; inputdata&lt;/code&gt; on the same system, where different builds of &lt;code&gt;sed&lt;/code&gt; have been compiled with different optimization flags and compilers. &lt;br&gt;
&lt;br&gt;
&#8226;&#xa0;In this case, why would I choose the mean &lt;code&gt;user&lt;/code&gt; time over mean &lt;code&gt;system&lt;/code&gt; time as the criterium for comparing against like measurements of a &quot;baseline&quot; stock build of &lt;code&gt;sed&lt;/code&gt;?&lt;br&gt;
&lt;br&gt;
&#8226; Likewise, what are the caveats with choosing one measurement class over the other? (What are the downsides of using &lt;code&gt;user&lt;/code&gt; time? &lt;code&gt;system&lt;/code&gt; time? I suspect the answer to this will depend upon the calls made.)&lt;br&gt;
&lt;br&gt;
If you have pointers to literature (other than the thousands of &lt;code&gt;man&lt;/code&gt; pages on Google) I&apos;d be appreciative of that advice, as well. Thanks in advance.</description>
  	<guid isPermaLink="false">post:ask.metafilter.com,2008:site.85347</guid>
  	<pubDate>Tue, 04 Mar 2008 23:24:33 -0800</pubDate>
  	<dc:creator>Blazecock Pileon</dc:creator>
	
	<category>unix</category>
	
	<category>time</category>
	
	<category>metric</category>
	
	<category>measurement</category>
	
	<category>sampling</category>
	
	<category>statistics</category>
	
	<category>performance</category>
	
	<category>benchmark</category>
	
	<category>benchmarking</category>
	
	<category>profiling</category>
	
</item>
<item>
  	<title>By: blender</title>
  	<link>http://ask.metafilter.com/85347/No-time-like-the-present#1261377</link>	
  	<description>Let me preface this by saying benchmarking is hard, fiddly, and the answer to any question about it is almost always &amp;quot;it depends&amp;quot;.&lt;br&gt;
&lt;br&gt;
I started typing a long explanation about user space vs kernel space and their interaction, but I think it&apos;d be more helpful to keep things simple.  System calls can be thought of as the API that the operating system provides to regular applications.  The standard library is mostly just a wrapper around these system calls.  On any UNIX, applications can only do a very limited subset of things themselves.  Anything like starting a process, raw memory allocation, I/O (including filesystem access) must perform a system call.&lt;br&gt;
&lt;br&gt;
Once you do a system call, you&apos;re no longer running your code.  Instead the processor is executing a system call handler somewhere in the innards of the operating system.  This is where the user/system distinction comes from.  User may roughly be thought of as &amp;quot;execution time within my application&amp;quot; while system may be thought of as &amp;quot;execution time within the kernel&amp;quot;.  &lt;br&gt;
&lt;br&gt;
The major caveat here is that if your process is suspended (eg it called select/read and is waiting on data), time stops being attributed to it, and the OS goes off and runs another process (or the idle loop) while it waits.  So both of these times refer only to time in which your application was actually running.&lt;br&gt;
&lt;br&gt;
Elapsed time refers to the wall clock.  The number of seconds of real time between the application starting and finishing.&lt;br&gt;
&lt;br&gt;
One additional problem is threaded applications.  The user and system time accrued by each thread is cumulative.  You can therefore easily see more user time elapsed time on a multiprocessor.&lt;br&gt;
&lt;br&gt;
In the specific example you&apos;ve given, I&apos;d probably take user time over wall time or system time.  If you&apos;re not changing how sed reads input, you want to compare how much faster/slower your changes have made it.&lt;br&gt;
&lt;br&gt;
User time will usually be your metric of interest (although elapsed time can be important if you&apos;re playing around with synchronization in user-space on a multithreaded app).  A high proportion of system time frequently indicates you are stressing the kernel and there might be a better way.&lt;br&gt;
&lt;br&gt;
But then you have other worries.  Is the machine in question quiesced?  Are the caches hot?  Is the bottleneck somewhere other than your code?  Are the workloads comparable?  Is the workload &amp;quot;representative&amp;quot; or is it some random corner case?&lt;br&gt;
&lt;br&gt;
Now... if you&apos;re on linux, please be aware that time sucks if you want detailed information about what&apos;s happening.  Look up &lt;a href=&quot;http://oprofile.sourceforge.net/news/&quot;&gt;oprofile&lt;/a&gt; instead, as this can show you where time is spent both in your app and in the kernel.  It can be more work to set up, but it&apos;s a very nice tool.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.85347-1261377</guid>
  	<pubDate>Wed, 05 Mar 2008 00:44:32 -0800</pubDate>
  	<dc:creator>blender</dc:creator>
</item>
<item>
  	<title>By: sergent</title>
  	<link>http://ask.metafilter.com/85347/No-time-like-the-present#1261420</link>	
  	<description>Everything blender said is true.&lt;br&gt;
&lt;br&gt;
Here are three programs which all take a few seconds to run but spend most of their time in different places.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://pastebin.com/f577bff80&quot;&gt;Lots of user time&lt;/a&gt;&lt;br&gt;
&lt;a href=&quot;http://pastebin.com/f39639db8&quot;&gt;Lots of system time&lt;/a&gt;&lt;br&gt;
&lt;a href=&quot;http://pastebin.com/f61e62746&quot;&gt;Very little user time or system time but high elapsed time&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
To get a realistic impression of how long the user has to wait for your program to finish, you probably want to look at &amp;quot;elapsed&amp;quot; but while running it on a machine where the bare minimum of other processes are running.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.85347-1261420</guid>
  	<pubDate>Wed, 05 Mar 2008 01:47:38 -0800</pubDate>
  	<dc:creator>sergent</dc:creator>
</item>
<item>
  	<title>By: grouse</title>
  	<link>http://ask.metafilter.com/85347/No-time-like-the-present#1261434</link>	
  	<description>Slightly adjunct to your question: I know you have talked about doing Python programming before here, and if you want to benchmark Python code, you may want to have a look at the &lt;code&gt;timeit&lt;/code&gt; module.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.85347-1261434</guid>
  	<pubDate>Wed, 05 Mar 2008 02:53:53 -0800</pubDate>
  	<dc:creator>grouse</dc:creator>
</item>
<item>
  	<title>By: blasdelf</title>
  	<link>http://ask.metafilter.com/85347/No-time-like-the-present#1261898</link>	
  	<description>Remember also that the &lt;tt&gt;time&lt;/tt&gt; you&apos;re using is almost definetly the one built into your shell (likely bash).  The GNU time utility supports a lot more features.&lt;br&gt;
&lt;br&gt;
That said, if you&apos;re benchmarking your own code you should really be profiling using the innards of the language you&apos;re using. What you find the bottlenecks to be will quite often surprise you.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.85347-1261898</guid>
  	<pubDate>Wed, 05 Mar 2008 11:21:13 -0800</pubDate>
  	<dc:creator>blasdelf</dc:creator>
</item>

    </channel>
</rss>
