def profile(queue_class): num_items = 5000 myQueue = queue_class(num_items) p = profiler.Profiler() for i in range(0, num_items): myQueue.push(i) print(queue_class.__name__ + ": add: " + str(p.get_seconds())) p = profiler.Profiler() for i in range(0, num_items): myQueue.pop() print(queue_class.__name__ + ": remove: " + str(p.get_seconds()))
def transform(self): """To apply a polyhedral-syntactic transformation on the annotated code""" # remove all existing annotations annot_re = r"/\*@((.|\n)*?)@\*/" self.annot_body_code = re.sub(annot_re, "", self.annot_body_code) # insert polysyn tags self.annot_body_code = self.__insertPolysynTags(self.annot_body_code) # parse the orio.module.body code assigns = parser.Parser().parse(self.module_body_code, self.line_no) # extract transformation information from the specified assignments tinfo = transf_info.TransfInfoGen().generate(assigns, self.perf_params) # perform polyhedral transformations ptrans = poly_transformation.PolyTransformation( Globals().verbose, tinfo.parallel, tinfo.tiles) pluto_code = ptrans.transform(self.annot_body_code) # use a profiling tool (i.e. gprof) to get hotspots information prof = profiler.Profiler( Globals().verbose, tinfo.profiling_code, tinfo.compile_cmd, tinfo.compile_opts, ) hotspots_info = prof.getHotspotsInfo(pluto_code) # parse the Pluto code to extract hotspot loops pluto_code = cloop_parser.CLoopParser().getHotspotLoopNests( pluto_code, hotspots_info) # expand all macro-defined statements pluto_code = macro_expander.MacroExpander().replaceStatements( pluto_code) # perform syntactic transformations strans = syn_transformation.SynTransformation( Globals().verbose, tinfo.permut, tinfo.unroll_factors, tinfo.scalar_replace, tinfo.vectorize, tinfo.rect_regtile, ) transformed_code = strans.transform(pluto_code) # return the transformed code return transformed_code
def trans_connect(host = 'localhost', debug=0): # try to optimize connection if on this machine if host != 'localhost': local_name = socket.gethostname() if string.find(local_name, '.') == -1: local_name = local_name + ".neotonic.com" if local_name == host: host = 'localhost' if debug: p = profiler.Profiler("SQL", "Connect -- %s:trans" % (host)) db = MySQLdb.connect(host = host, user=USER, passwd = PASSWORD, db=DATABASE) if debug: p.end() retval = DB(db, debug=debug) return retval
def profile_for_graph(queue_class): # Run this then copy the output into Excel and create a line graph for each class that was profiled print("Profiling class: " + queue_class.__name__) for num_items in range(100,10000,100): p = profiler.Profiler() myQueue = queue_class(num_items) for i in range(0, num_items): myQueue.push(i) for i in range(0, num_items): myQueue.pop() print(p.get_seconds())
def main(): p = profiler.Profiler() directory = 'trainingData/Dikens/DavidCopperfield' outputFile = "results/authorProfiles.txt" with open(outputFile, 'w') as textFile: for root, dirs, files in os.walk(directory): for myfile in files: if myfile.endswith(".txt"): fullPath = os.path.join(root, myfile) resultForDikens = p.getProfile(fullPath, 'Dikens') textFile.write(str(resultForDikens) + '\n') textFile.close directory = 'trainingData/Joyce/Ulysses_Dubliners' with open(outputFile, 'a') as textFile: for root, dirs, files in os.walk(directory): for myfile in files: if myfile.endswith(".txt"): fullPath = os.path.join(root, myfile) resultForJoyce = p.getProfile(fullPath, 'Joyce') textFile.write(str(resultForJoyce) + '\n') textFile.close
colordisp = display.add_method( displaymethods.CenterFillDisplay(outputClones.posOutput, outputClones.MaterialColorOutput)) colordisp.set_param('colormap', color.graymap) if do_edges: edgedisp = display.add_method( displaymethods.EdgeDisplay(outputClones.posOutput)) edgedisp.set_param('width', 0.001) edgedisp.set_param('color', color.Gray(0.5)) if do_contours: cdisp = display.add_method( contourdisplay.PlainContourDisplay(outputClones.posOutput, funcOutput)) cdisp.set_param('width', 0.005) cdisp.set_param('color', color.blue) cdisp.set_param('levels', nlevels) cdisp.set_param('nbins', contourbins) # get an output device import psoutput device = psoutput.PSoutput(psfilename) if proffile: import profiler prof = profiler.Profiler(proffile) display.draw(mesh, device) if proffile: prof.stop()
import logging import profiler iterations = 1000 l = logging.getLogger(__name__) l.addHandler(logging.NullHandler()) l.setLevel(logging.INFO) l.disabled = True with profiler.Profiler(enabled=True, contextstr="lazy logging") as p: for i in range(iterations): l.info("Hello There.") p.print_profile_data()
def testCommaIndex(self): p = profiler.Profiler() commaIndexlower = p.getCommaIndex("abc, xyz") self.assertEqual(commaIndexlower, 50)
def testAverage(self): p = profiler.Profiler() testAvgMiddle = self.p.calculateAvg([5, 10, 15]) testAvgZero = self.p.calculateAvg([0]) self.assertEqual(testAvgMiddle, 10) self.assertEqual(testAvgZero, 0)
start = mid + 1 elif l[mid] > item_searched_for: # Item can't be in the second half of the part of the list we're looking at end = mid - 1 steps += 1 if l[mid] == item_searched_for: return mid, steps else: return -1, steps if __name__ == '__main__': my_list = [] p = profiler.Profiler() for i in range(0, 10000000): my_list.append(random.randint(-4e9, 4e9)) # 4e9 = 4 * 10^9 i.e. 4 billion print("List add time: " + str(p.get_seconds())) p = profiler.Profiler() my_list.sort() print("Sort time: " + str(p.get_seconds())) p = profiler.Profiler() result = linear_search(my_list, 1) print("Linear search time: " + str(p.get_seconds())) print("Linear search result: " + str(result)) p = profiler.Profiler()
df = pd.concat([pd.read_csv(csv) for csv in csvs]) #shuffle df['HogFamA'] = df.HogA.map(hashutils.hogid2fam) df['HogFamB'] = df.HogB.map(hashutils.hogid2fam) df = df.sample(frac=1) traindf = df.iloc[:ntrain, :] testdf = df.iloc[ntrain:ntest, :] validation = df.iloc[ntest:, :] validation.to_csv(savedir + 'validationset.csv') print(traindf) print(testdf) traintest = None if 'forest' in args and 'hashes' in args: p = profiler.Profiler(hashes=args['hashes'], forest=args['forest'], oma=True) else: p = profiler.Profiler(lshforestpath, hashes_path, oma=True) chunksize = 25 tstart = t.time() gendata = p.retmat_mp(traindf, nworkers=8, chunksize=25) xtotal = [] ytotal = [] print('generate data for training') for i in range(int(ntrain + ntest / chunksize)): try: X, y = next(gendata) xtotal.append(X) ytotal.append(y)
if do_contours: cdisp = display.add_method( contourdisplay.PlainContourDisplay(outputClones.posOutput, funcOutput)) cdisp.set_param('width', 0.005) cdisp.set_param('color', color.blue) cdisp.set_param('levels', nlevels) cdisp.set_param('nbins', contourbins) # get an output device import psoutput device = psoutput.PSoutput(psfilename) display.draw(mesh, device) ##import profile ##import time ##p = profile.Profile(time.time) ##p.run('run()') ##p.dump_stats('profile.prof') import oofpath import profiler p = profiler.Profiler('testprofiler.prof') run() p.stop() ##run()
def __init__(self): print("game.__init__()") Game.singleton = self self.game_started = time.time() self.game_time = 0.0 self.delta_time = 0.0001 self.graphics_options = { 'Fade in props': True, 'Prop distance': 10, 'Grass distance': 10, 'HDR': False, 'Bloom': False, 'DOF': False, 'SSAO': True, 'SSAO_samples': 3, 'SSAA': False, 'Color': False, 'Motion Blur': False, 'Fog': True, 'camera_clip': 1000, } self.game_options = { 'Difficulty': 1, 'Hardcore': False, } self.sound_options = { 'Effect Volume': 1.0, 'Music Volume': 1.0, 'Voice Volume': 1.0, } self.control_options = {\ Game.FORWARD_KEY: bge.events.WKEY, Game.BACKWARD_KEY: bge.events.SKEY, Game.STRAFE_LEFT_KEY: bge.events.AKEY, Game.STRAFE_RIGHT_KEY: bge.events.DKEY, Game.ACTION_KEY: bge.events.EKEY, Game.SWITCH_WEAPON_KEY: bge.events.FKEY, Game.JUMP_KEY: bge.events.SPACEKEY, Game.RUN_KEY: bge.events.LEFTSHIFTKEY, Game.AIM_WEAPON_KEY: bge.events.RIGHTMOUSE, Game.SHOOT_WEAPON_KEY: bge.events.LEFTMOUSE, Game.MOUSE_SENSITIVITY: 5.0, } self.mandatory_blends = [ './data/models/weapons/P90.blend', './data/models/weapons/F2000.blend', './data/models/entities/Mouselook4.blend', './data/models/entities/player_file.blend' ] self.default_cell = 'terrain.cell' item.load_items() self.load_prefs() self.world = world.World() self.console = console_.Console(safepath('./data/fonts/phaisarn.ttf'), bge.events.ACCENTGRAVEKEY) self.profiler = profiler.Profiler() self.sound_manager = sound_manager.SoundManager() self.ui_manager = ui.UIManager() self.savefile = None self.fx_object = bge.logic.getCurrentScene().objects['FX'] self.fx_object_blur = bge.logic.getCurrentScene().objects['FX BLUR'] self.ui_manager.show('hud') self.ui_manager.show('pause') # SUDO setup sudo.game = self sudo.world = self.world sudo.player = self.world.player sudo.cell_manager = self.world.cell_manager sudo.entity_manager = self.world.entity_manager sudo.hash = sudo.entity_manager.hash sudo.profiler = self.profiler sudo.sound_manager = self.sound_manager sudo.ui_manager = self.ui_manager
] col = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) vel = (random.randrange(-1, 1), random.randrange(-1, 1)) cell_x = (pos[0] - world_left) // cell_size cell_y = (pos[1] - world_top) // cell_size point = [pos, col, vel, cell_x, cell_y] points.append(point) cells[cell_y][cell_x].append(point) image_idx = 0 line_profiler = profiler.Profiler() frame_profiler = profiler.Profiler() while True: for py in range(0, screen_size[1]): for px in range(0, screen_size[0]): for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close sys.exit() best_dist_sq = 1e9**2 px_world_space = (px - world_left) py_world_space = (py - world_top) cell_x = px_world_space // cell_size cell_y = py_world_space // cell_size nearest_point = None
def profile_good_dictionary(num_items, hash_function, num_buckets=10000): test_dictionary = GoodDictionary(hash_function, num_buckets) p = profiler.Profiler() for i in range(0, num_items): test_dictionary.set(str(i), 0) return p.get_seconds(), test_dictionary.get_bucket_usage_percent()
def profile_bad_dictionary(num_items): p = profiler.Profiler() for i in range(0, num_items): bad_dictionary_set(str(i), 0) return p.get_seconds()