from timeit import Timer import ctime # remove stuff to not test funcs = list(ctime.__all__) funcs.remove("sleep") funcs.remove("accept2dyear") funcs.remove("timezone") funcs.remove("daylight") funcs.remove("tzname") funcs.remove("altzone") funcs.remove("struct_time") for f in funcs: tocall = "%s()" % f toimport = "from time import %s" % f timer = Timer(tocall, toimport) toimport = "from ctime import %s" % f ctimer = Timer(tocall, toimport) print "time.%s(): %s" % (f, timer.timeit()) print "ctime.%s(): %s" % (f, ctimer.timeit()) print