def toStringDuration(duration):
    """Returns a description of the given duration in the most appropriate
    units (e.g. seconds, ms, us, or ns).
    """
    table = ('%dms', 0.001, 1000.0), (u'%dμs', 1e-06, 1000000.0), ('%dns', 
        1e-09, 1000000000.0)
    if duration > 1:
        return '%fs' % duration
    for format, threshold, factor in table:
        if duration > threshold:
            return format % int(duration * factor)
    return '%fs' % duration
