def format_duration(time):
    """format duration, unit of input time should be 'second'."""
    fmt = ''
    if time < 1:
        fmt = '{:.3f} ms'.format(time * 1000)
    elif time >= 1 and time < 60:
        fmt = '{:.3f} sec'.format(time)
    elif time >= 60 and time < 3600:
        min = int(time / 60)
        sec = time - min * 60
        fmt = '{:d} min {:.3f} sec'.format(min, sec)
    elif time >= 3600 and time < 86400:
        hour = int(time / 3600)
        min = int((time - hour * 3600) / 60)
        sec = time - hour * 3600 - min * 60
        fmt = '{:d} hour {:d} min {:.3f} sec'.format(hour, min, sec)
    else:
        day = int(time / 86400)
        hour = int((time - day * 86400) / 3600)
        min = int((time - day * 86400 - hour * 3600) / 60)
        sec = time - day * 86400 - hour * 3600 - min * 60
        fmt = '{:d} day {:d} hour {:d} min {:.3f} sec'.format(day, hour,
            min, sec)
    return fmt
