def getTimeDiffs(times, timenames=None, fmt='%0.4f', percs=0):
    """Returns a string of time diffs between the given list of times, as well as the total time.
    If a list of `timenames` is given, then those are used as the names for each time diff.
    If `percs` is true, then also shows the percentage of time for each piece.

    Example::

        times = [time.time()]
        foo()
        times.append(time.time())
        bar()
        times.append(time.time())
        baz()
        times.append(time.time())
        print getTimeDiffs(times)
    """
    if len(times) < 2: return ''
    total = times[-1]-times[0]
    if percs:
        pfmt = fmt+' (%0.1f%%)'
        difs = [pfmt % (next-prev, 100.0*(next-prev)/total) for next, prev in zip(times[1:], times)]
    else:
        difs = [fmt % (next-prev) for next, prev in zip(times[1:], times)]
    if timenames:
        difs = ['%s=%s' % (n, d) for n, d in zip(timenames, difs)]
        difs = ', '.join(difs)
    else:
        difs = '+'.join(difs)
    return '%s=%ss' % (difs, fmt % (total))