<s> from django . conf import settings <EOL> from django . test . simple import DjangoTestSuiteRunner <EOL> try : <EOL> from django . utils . encoding import force_unicode <EOL> except ImportError : <EOL> force_unicode = str <EOL> import operator <EOL> import time <EOL> from django . utils . unittest import TestSuite <EOL> TIMINGS = { } <EOL> def time_it ( func ) : <EOL> def _inner ( * args , ** kwargs ) : <EOL> start = time . time ( ) <EOL> func ( * args , ** kwargs ) <EOL> end = time . time ( ) <EOL> TIMINGS [ force_unicode ( func ) ] = end - start <EOL> return _inner <EOL> class TimingSuite ( TestSuite ) : <EOL> def addTest ( self , test ) : <EOL> test = time_it ( test ) <EOL> super ( TimingSuite , self ) . addTest ( test ) <EOL> class TimedTestRunner ( DjangoTestSuiteRunner ) : <EOL> def build_suite ( self , test_labels , extra_tests = None , ** kwargs ) : <EOL> suite = super ( TimedTestRunner , self ) . build_suite ( test_labels , extra_tests , ** kwargs ) <EOL> return TimingSuite ( suite ) <EOL> def teardown_test_environment ( self , ** kwargs ) : <EOL> super ( TimedTestRunner , self ) . teardown_test_environment ( ** kwargs ) <EOL> by_time = sorted ( <EOL> TIMINGS . items ( ) , <EOL> key = operator . itemgetter ( <NUM_LIT:1> ) , <EOL> reverse = True ) [ : <NUM_LIT:10> ] <EOL> print ( u"<STR_LIT>" ) <EOL> for func_name , timing in by_time : <EOL> print ( u"<STR_LIT>" . format ( f = func_name , t = timing ) ) </s>
