I'm trying to convert seconds to milliseconds (or microseconds) without dividing by 1,000 or 1,000,000. The reason I'm doing it is because I don't want the decimal point to be shown. Is there a way of showing milliseconds or microseconds without the decimal point and without dividing by 1,000 or 1,000,000?
Here's my code with method execution timing:
from random import randint list = [1]*1000 for i in range (1, 1000): list[i] = randint(1,100) def insertion(list): for index in range(1,len(list)): value = list[index] i = index - 1 while i>=0 and (value < list[i]): list[i+1] = list[i] list[i] = value i = i - 1 def test(): start = time.clock() insertion(list) elapsed = (time.clock() - start) print "Time taken for insertion = ", elapsed if __name__ == '__main__': import time test()
timeitmodule.print "Time taken for insertion = {:.0f}".format(elapsed). Then it doesn't matter what type you have.nis anint,n / 1000is aninttoo (unless you use a__future__statement). If you want to be absolutely sure, use the explicit "floordiv" operator:n // 1000is aninteven in 3.x.