def format_time(arg):
    """Format timespans from seconds to smaller units with the right units"""
    if arg <= 1e-06:
        return '{}ns'.format(int(arg * 1000000000))
    elif arg <= 0.001:
        return '{}μs'.format(int(arg * 1000000))
    elif arg <= 1:
        return '{}ms'.format(int(arg * 1000))
    else:
        return '{}s'.format(int(arg))
