Title / Description
Code 05 import time 06 def timing ( f , n ): 07 print f . __name__ , n , "times" , 08 r = range ( n ) 09 t1 = time . clock () 10 for i in r : 11 f () 12 t2 = time . clock () 13 print round ( t2 - t1 , 3 ) 14 15 #用法 16 def to_be_tested (): 17 a = [] 18 for i in range ( 0 , 1000 ): 19 a . append ( i ) 20 21 timing ( to_be_tested , 10000 ) 22 #result: to_be_tested 10000 times 2.451
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code