Ruby
code posted
created at 04 Jun 09:42, updated at 11 Jun 17:53
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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 |
463 Bytes in 4 ms with coderay