title: Performance profiling tools for shell scripts
body: <p>I'm attempting to speed up a collection of scripts that invoke subshells and do all sorts of things. I was wonder if there are any tools available to time the execution of a shell script and its nested shells and report on which parts of the script are the most expensive.</p>
  
  <p>For example, if I had a script like the following.</p>
  
  <pre><code>#!/bin/bash
  
  echo "hello"
  echo $(date)
  echo "goodbye"
  </code></pre>
  
  <p>I would like to know how long each of the three lines took. <code>time</code> will only only give me total time for the script. <code>bash -x</code> is interesting but does not include timestamps or other timing information.</p>