<s> from kivy . app import App <EOL> from kivy . uix . floatlayout import FloatLayout <EOL> from kivy . lang import Builder <EOL> from kivy . resources import resource_find <EOL> from kivy . clock import Clock <EOL> import timeit <EOL> Builder . load_string ( '''<STR_LIT>''' ) <EOL> class PerfApp ( App , FloatLayout ) : <EOL> def build ( self ) : <EOL> return self <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( PerfApp , self ) . __init__ ( ** kwargs ) <EOL> self . tests = [ ] <EOL> tests = ( self . load_large_text , self . stress_insert , <EOL> self . stress_del , self . stress_selection ) <EOL> for test in tests : <EOL> but = type ( self . but ) ( text = test . __name__ ) <EOL> self . but . parent . add_widget ( but ) <EOL> but . test = test <EOL> self . tests . append ( but ) <EOL> self . test_done = True <EOL> def load_large_text ( self , * largs ) : <EOL> print ( '<STR_LIT>' ) <EOL> self . test_done = False <EOL> fd = open ( resource_find ( '<STR_LIT>' ) , '<STR_LIT:r>' ) <EOL> print ( '<STR_LIT>' ) <EOL> def load_text ( * l ) : <EOL> self . text_input . text = fd . read ( ) <EOL> t = timeit . Timer ( load_text ) <EOL> ttk = t . timeit ( <NUM_LIT:1> ) <EOL> fd . close ( ) <EOL> import resource <EOL> print ( '<STR_LIT>' ) <EOL> print ( resource . getrusage ( resource . RUSAGE_SELF ) . ru_maxrss / <NUM_LIT> , '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , len ( self . text_input . _lines ) , '<STR_LIT>' , ttk , '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> self . test_done = True <EOL> def stress_del ( self , * largs ) : <EOL> self . test_done = False <EOL> text_input = self . text_input <EOL> self . lt = len_text = len ( text_input . text ) <EOL> target = len_text - ( <NUM_LIT> * <NUM_LIT:9> ) <EOL> self . tot_time = <NUM_LIT:0> <EOL> def dlt ( * l ) : <EOL> if len ( text_input . text ) <= target : <EOL> Clock . unschedule ( dlt ) <EOL> print ( '<STR_LIT>' ) <EOL> m_len = len ( text_input . _lines ) <EOL> print ( '<STR_LIT>' ) <EOL> import resource <EOL> print ( '<STR_LIT>' ) <EOL> print ( resource . getrusage ( resource . RUSAGE_SELF ) . ru_maxrss <EOL> / <NUM_LIT> , '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , m_len ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , self . tot_time ) <EOL> print ( '<STR_LIT>' ) <EOL> self . test_done = True <EOL> return <EOL> text_input . select_text ( self . lt - <NUM_LIT> , self . lt - <NUM_LIT:10> ) <EOL> text_input . delete_selection ( ) <EOL> self . lt -= <NUM_LIT> <EOL> text_input . scroll_y -= <NUM_LIT:100> <EOL> self . tot_time += l [ <NUM_LIT:0> ] <EOL> Clock . schedule_once ( dlt ) <EOL> Clock . schedule_once ( dlt ) <EOL> def stress_insert ( self , * largs ) : <EOL> self . test_done = False <EOL> text_input = self . text_input <EOL> text_input . select_all ( ) <EOL> text_input . _copy ( text_input . selection_text ) <EOL> text_input . cursor = text_input . get_cursor_from_index ( <EOL> text_input . selection_to ) <EOL> len_text = len ( text_input . _lines ) <EOL> self . tot_time = <NUM_LIT:0> <EOL> def pste ( * l ) : <EOL> if len ( text_input . _lines ) >= ( len_text ) * <NUM_LIT:9> : <EOL> Clock . unschedule ( pste ) <EOL> print ( '<STR_LIT>' ) <EOL> m_len = len ( text_input . _lines ) <EOL> print ( '<STR_LIT>' , len_text , '<STR_LIT>' , <EOL> round ( ( m_len - len_text ) / len_text ) , '<STR_LIT>' ) <EOL> import resource <EOL> print ( '<STR_LIT>' ) <EOL> print ( resource . getrusage ( resource . RUSAGE_SELF ) . ru_maxrss <EOL> / <NUM_LIT> , '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , m_len ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , self . tot_time ) <EOL> print ( '<STR_LIT>' ) <EOL> self . test_done = True <EOL> return <EOL> self . tot_time += l [ <NUM_LIT:0> ] <EOL> text_input . _paste ( ) <EOL> Clock . schedule_once ( pste ) <EOL> Clock . schedule_once ( pste ) <EOL> def stress_selection ( self , * largs ) : <EOL> self . test_done = False <EOL> text_input = self . text_input <EOL> self . tot_time = <NUM_LIT:0> <EOL> old_selection_from = text_input . selection_from - <NUM_LIT> <EOL> def pste ( * l ) : <EOL> if text_input . selection_from >= old_selection_from : <EOL> Clock . unschedule ( pste ) <EOL> print ( '<STR_LIT>' ) <EOL> import resource <EOL> print ( '<STR_LIT>' ) <EOL> print ( resource . getrusage ( resource . RUSAGE_SELF ) . ru_maxrss <EOL> / <NUM_LIT> , '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , self . tot_time ) <EOL> print ( '<STR_LIT>' ) <EOL> self . test_done = True <EOL> return <EOL> text_input . select_text ( text_input . selection_from - <NUM_LIT:1> , <EOL> text_input . selection_to ) <EOL> Clock . schedule_once ( pste ) <EOL> Clock . schedule_once ( pste ) <EOL> def start_test ( self , * largs ) : <EOL> self . but . text = '<STR_LIT>' <EOL> self . slider . max = len ( self . tests ) <EOL> def test ( * l ) : <EOL> if self . test_done : <EOL> try : <EOL> but = self . tests [ int ( self . slider . value ) ] <EOL> self . slider . value += <NUM_LIT:1> <EOL> but . state = '<STR_LIT>' <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , but . text ) <EOL> print ( '<STR_LIT>' ) <EOL> but . test ( but ) <EOL> except IndexError : <EOL> for but in self . tests : <EOL> but . state = '<STR_LIT>' <EOL> self . but . text = '<STR_LIT>' <EOL> self . slider . value = <NUM_LIT:0> <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> Clock . unschedule ( test ) <EOL> Clock . schedule_interval ( test , <NUM_LIT:1> ) <EOL> if __name__ in ( '<STR_LIT:__main__>' , ) : <EOL> PerfApp ( ) . run ( ) </s>
