def unit(x):
    """
    Optimizes the rendering of time.

    .. runpython::
        :showcode:

        from jupytalk.benchmark.mlprediction import unit

        print(unit(34))
        print(unit(3.4))
        print(unit(0.34))
        print(unit(0.034))
        print(unit(0.0034))
        print(unit(0.00034))
        print(unit(0.000034))
        print(unit(0.0000034))
        print(unit(0.00000034))
    """
    if x >= 1:
        return "%1.2f s" % x
    elif x >= 1e-3:
        return "%1.2f ms" % (x * 1000)
    elif x >= 1e-6:
        return "%1.2f µs" % (x * 1000**2)
    elif x >= 1e-9:
        return "%1.2f ns" % (x * 1000**3)
    else:
        return "%1.2g s" % x