def process(self, value): """Returns minmax (tuple) for a number of samples after the first level change has occurred, otherwise None""" if self._level_change_time is not None: if (get_time() - self._level_change_time) >= self._duration_in_sec: return tuple(self._minmax) if value > self._minmax[1]: self._minmax[1] = value elif value < self._minmax[0]: self._minmax[0] = value elif self._minmax[0] != value: # level change just occurred self._level_change_time = get_time() return self.process(value) return None
def profile_time(a_degree=4, b_degree=4, c_degree=4): print(f'Profiling ASGarD\'s compute time for {PDE}...') # The output sheet describing time data time_sheet = TimeSheet() # The function describing the time used for each level for every degree f = Function(degree=2) # a quadratic function # a list containing the terms of the function describing time used as a function of degree per level level_terms = [] # Iterate over level and degrees for the PDE for level in tqdm(LEVELS, desc=f'Total progress'): for i, degree in enumerate(tqdm(DEGREES, leave=False, desc=f'Level {level}')): seconds = [] for _ in range(3): seconds.append(get_time(level, degree, PDE)) average_seconds = sum(seconds) / len(seconds) # time as a function of degree per level f.add_point(i, average_seconds) time_sheet.add_seconds(level, degree, average_seconds) # add to the list of the list of terms per level's time function level_terms.append(f.as_terms()) # clear the current f to reuse for the next level's time function f.clear() # Functions describing the a, b, and c terms of the function describing seconds used a = Function(degree=a_degree) b = Function(degree=b_degree) c = Function(degree=c_degree) # Add the points for the a, b, and c functions for i, terms in enumerate(level_terms): a.add_point(i, terms[0]) b.add_point(i, terms[1]) c.add_point(i, terms[2]) return a, b, c, time_sheet
def is_sampling_for_minmax(self): """true true if currently sampling for minmax""" return (self._level_change_time is not None) and \ (get_time() - self._level_change_time) < self._duration_in_sec
#print sort.check_sorted(list,False) # print '\ntesting and timing for a large array\n' list_large = [] for i in range(5000): list_large.append(random.randint(1, 100)) print 'size:5000, for the slower ones' timer = timer.Timer(time.clock()) #initialize the timer print 'bubble sort\n' list = sort.bubble_sort(list_large[:]) assert sort.check_sorted(list) timer.get_time(time.clock()) print '' print 'insertion sort\n' list = sort.insert_sort(list_large[:]) assert sort.check_sorted(list) timer.get_time(time.clock()) print '' print 'insertion sort fast\n' list = sort.insert_sort_fast(list_large[:]) assert sort.check_sorted(list) timer.get_time(time.clock()) print '' print 'heap sort\n'