title: How to get memory usage high water mark on OSX
body: <p>I'd like to be able to test some guesses about memory complexity of various command line utilities.</p>
  
  <p>Taking as a simple example</p>
  
  <pre><code>grep pattern file
  </code></pre>
  
  <p>I'd like to see how memory usage varies with the size of <code>pattern</code> and the size of <code>file</code>.</p>
  
  <p>For time complexity, I'd make a guess, then run</p>
  
  <pre><code>time grep pattern file
  </code></pre>
  
  <p>on various sized inputs to see if my guess seems to be borne out in reality, but I don't know how to do this for memory.</p>
  
  <p>One possibility would be a wrapper script that initiates the job and samples memory usage periodically, but this seems inelegant and unlikely to give the real high watermark.</p>
  
  <p>I've seen <code>time -v</code> suggested, but don't have that flag available on my machine (running bash on OSX) and don't know where to find a version that supports it.</p>
  
  <p>I've also seen that on Linux this information is available through the <code>proc</code> filesystem, but again, it's not available to me in my context.</p>
  
  <p>I'm wondering if <code>dtrace</code> might be an appropriate tool, but again am concerned that a simple sample-based figure might not be the true high watermark?</p>
  
  <p>Does anyone know of a tool or approach that would be appropriate on OSX?</p>
  
  <p><strong>Edit</strong> </p>
  
  <p>I removed two mentions of <em>disk usage</em>, which were just asides and perhaps distracted from the main thrust of the question.</p>