def test_largescale(): s = Stopwatch() integration_factor = 5 device_map = device_parser.build_device_map(device_parser.parse_data('test.xml')) test_size = 10000 histogram = OrderedDict() for i in range(5): time = 0.0 for j in range(5): s.start() generate_test_input(device_map, test_size, file_name='test_input1.csv') s.stop() print('Generating test input of size {}: '.format(test_size), s.read()) s.reset() s.start() analyze_data_nograph('csvs/test_input1.csv', integration_factor, device_map) s.stop() print('Processing input of size {}: '.format(test_size), s.read()) time += s.read() s.reset() print('Average time for input of size {}: '.format(test_size), time/5) histogram[test_size] = time/5 test_size *= 2 print(histogram) for i,j in histogram.items(): print(' size | time ') print('{0:5d}|{1:5f}'.format(i,j))
def evaluate(self,times=None): results = [] s = Stopwatch() times = times if times != None else self._times for i in range(times): self._setup() s.reset() gc.disable() s.start() self._code() gc.enable() results.append(s.read()) self._evaluate_results = [(min(results),sum(results)/times,max(results))] + [results] return self._evaluate_results
import prompt from stopwatch import Stopwatch original_number = prompt.for_int('Enter a positive number', is_legal=(lambda x : x > 0)) is_debugging = prompt.for_bool('Display intermediate results',True) cycle_count = 1 test_number = original_number timer = Stopwatch(running_now = True) while True: if is_debugging: print('Cycle', cycle_count, ': test number is now', test_number) #################### if test_number == 1336: break #################### cycle_count += 1 if test_number % 2 == 0: test_number = test_number // 2 else: test_number = 3*test_number + 1 timer.stop() print('\n\nFor test number =',original_number,'cycles to 1 =',cycle_count) print('Process took', timer.read(), 'seconds')
def create_random(size: int = 0) -> list: out_list = [] for i in range(size): out_list.append((random.random(), random.random())) return out_list coor_list = create_random(25600) def perform_task(): closest_2d(coor_list) cProfile.run("perform_task()", "profile") p = pstats.Stats('profile') p.strip_dirs().sort_stats('calls').print_stats(12) p.strip_dirs().sort_stats('time').print_stats(12) print("run without profiling started...") timer = Stopwatch() gc.disable() timer.start() closest_2d(coor_list) timer.stop() gc.enable() print('Time =', timer.read())
while (True): #Roll until roll point (win) or 7 (lose) roll = dice.roll().pip_sum() #print(roll) if roll == point: #If made the point first win_count += 1 count += 1 if (point == 10): print(game) #...win and this game is over break elif roll == 7: #If roll a 7 first lose_count += 1 #...lose and this game is over break game_timer.stop() ##Display Statistics print(' Raw Wins/Lose =', '{:,}'.format(win_count), '/', '{:,}'.format(lose_count)) print(' % Wins/Lose =', 100.0 * win_count / (win_count + lose_count), '/', 100.0 * lose_count / (win_count + lose_count)) print() print(' Dice Thrown =', '{:,}'.format(dice.rolls())) print(' Avg Dice/game =', dice.rolls() / games_to_play) print() print(' Elapsed Time =', game_timer.read(), 'seconds') print(' Speed =', '{:,}'.format(int(games_to_play / game_timer.read())), 'games/second')
import prompt from stopwatch import Stopwatch original_number = prompt.for_int('Enter a positive number', is_legal=(lambda x : x > 0)) is_debugging = prompt.for_bool('Display intermediate results',True) cycle_count = 1 test_number = original_number timer = Stopwatch(running_now = True) while True: if is_debugging: print('Cycle', cycle_count, ': test number is now', test_number) #################### if test_number == 1: break; #################### cycle_count += 1 if test_number % 2 == 0: test_number = test_number // 2 else: test_number = 3*test_number + 1 timer.stop() print('\n\nFor test number =',original_number,'cycles to 1 =',cycle_count) print('Process took', timer.read(), 'seconds')
elif first_roll == 2 or first_roll == 3 or first_roll == 12: lose_count += 1 #Lose on the first roll with 2, 3, or 12 else: #Try to make the point as the game continues point = first_roll #point will never store 7, 11, 2, 3, or 12 while(True): #Roll until roll point (win) or 7 (lose) roll = dice.roll().pip_sum() if roll == point: #If made the point first win_count += 1 #...win and this game is over break elif roll == 7: #If roll a 7 first lose_count+= 1 #...lose and this game is over break game_timer.stop(); ##Display Statistics print(' Raw Wins/Lose =', '{:,}'.format(win_count), '/', '{:,}'.format(lose_count)) print(' % Wins/Lose =', 100.0*win_count/(win_count+lose_count), '/', 100.0*lose_count/(win_count+lose_count)) print() print(' Dice Thrown =', '{:,}'.format(dice.rolls())) print(' Avg Dice/game =', dice.rolls()/games_to_play) print() print(' Elapsed Time =' , game_timer.read(), 'seconds') print(' Speed =', '{:,}'.format(int(games_to_play/game_timer.read())), 'games/second')