I haven't written python for a while, and I have studied. Net in my spare time and helped my friends solve some problems. In this way, Python has not been touched for nearly two months. (* ^__ ^ *), This articleArticleIt is also written for. NET as an internal chain. Record it by the way.
PythonCommunityThere is a saying: "Python has its own battery ." Do not write the timing framework by yourself. Python 2.3 and later have a perfect timing tool called timeit. Example in diveinto
>>> Import timeit >>> T = timeit. timer ("soundex. soundex ('pilgrim ')",... "Import soundex") >>> T. timeit () 8.21683733547 >>> T. repeat (3, 2000000) [16.48319309109, 16.46128984923, 16.44203948912]
This method has limitations. Sometimes I just want to count the timing of a certain section of the method. At this time, it is more convenient to use time. Clock. Similar to stopwatch in. net
Import timen = 100000st = time. clock () V = ('abcd', 100, 1.0, ['pumayd', 100, none]) for I in xrange (n): exec (dumps (v )) print 'pickle' usage', time. clock ()-St