def timeProcess(string, options): numlines = len(string.splitlines()) print "Testing file with", numlines, "lines" t = time.clock() indent_mode(string, options) dt = time.clock() - t print "Indent Mode:", dt, "s" t = time.clock() paren_mode(string, options) dt = time.clock() - t print "Paren Mode:", dt, "s" cProfile.runctx("indent_mode(string, options)", globals(), locals()) cProfile.runctx("paren_mode(string, options)", globals(), locals())
def timeProcess(name, string, options): numlines = len(string.splitlines()) numchars = len(string) print("Processing", name, ":", numlines, "lines", numchars, "chars") t = time.perf_counter() indent_mode(string, options) dt = (time.perf_counter() - t) * 1000 print("indent:", '{:.3f}'.format(dt), "ms") t = time.perf_counter() paren_mode(string, options) dt = (time.perf_counter() - t) * 1000 print("paren:", '{:.3f}'.format(dt), "ms") t = time.perf_counter() smart_mode(string, options) dt = (time.perf_counter() - t) * 1000 print("smart:", '{:.3f}'.format(dt), "ms") print()
def run(self, edit): # run Paren Mode on the whole file whole_region = sublime.Region(0, self.view.size()) all_text = self.view.substr(whole_region) result = paren_mode(all_text, None) # TODO: # - what to do when paren mode fails on a new file? # show them a message? # - warn them before applying Paren Mode changes? if result['success']: # update the buffer if we need to if all_text != result['text']: self.view.replace(edit, whole_region, result['text']) # drop them into Indent Mode self.view.set_status(STATUS_KEY, INDENT_STATUS)
def on_load(self, view): # exit early if we do not recognize this file extension if not self.should_start(view): return # run Paren Mode on the whole file whole_region = sublime.Region(0, view.size()) all_text = view.substr(whole_region) result = paren_mode(all_text, None) # TODO: # - what to do when paren mode fails on a new file? # show them a message? # - warn them before applying Paren Mode changes? if result['success']: # update the buffer if we need to if all_text != result['text']: e = view.begin_edit() view.replace(e, whole_region, result['text']) view.end_edit(e) # drop them into Indent Mode view.set_status(STATUS_KEY, INDENT_STATUS)
def on_load(self, view): # exit early if we do not recognize this file extension if not self.should_start(view): return # run Paren Mode on the whole file whole_region = sublime.Region(0, view.size()) all_text = view.substr(whole_region) result = paren_mode(all_text, None) # TODO: # - what to do when paren mode fails on a new file? # show them a message? # - warn them before applying Paren Mode changes? if result["success"]: # update the buffer if we need to if all_text != result["text"]: e = view.begin_edit() view.replace(e, whole_region, result["text"]) view.end_edit(e) # drop them into Indent Mode view.set_status(STATUS_KEY, INDENT_STATUS)