"""This is a template file for using the timeit module.

   The timeit module can process stings as well as callables. The second
   testing routine uses that.

"""


test_a = """\
        # Some Python code, e.g.,
        "-".join(str(n) for n in range(1000))
        """

test_b = """\
        # Some Python code, e.g.,
        "-".join([str(n) for n in range(1000)])
        """

test_names = {test_a: "test_a", test_b: "test_b"}


if __name__ == '__main__':

    import timeit

    repeat = 5
    number = 1000
    unit = "msec"
    unittosec = {"usec": 1e6, "msec": 1000, "sec": 1}

    for test in [test_a, test_b]:
        res = timeit.repeat(
            test,
            setup="import math" ,
            repeat=repeat, number=number)
        print("%s: %d loops, best of %d: %.3g %s per loop" %
              (test_names[test],
               number, repeat,
               min(res) / number * unittosec[unit],
               unit))
