import math


def _pretty_print_time(t):
    """ Print time with units """
    units = [u"s", u"ms", u'us', "ns"]
    scaling = [1, 1e3, 1e6, 1e9]
    if t > 0.0 and t < 1000.0:
        order = min(-int(math.floor(math.log10(t)) // 3), 3)
    elif t >= 1000.0:
        order = 0
    else:
        order = 3
    return "%.3g %s" % (t * scaling[order], units[order])