| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,10 +43,10 @@ def end_test(self): | |||
| 43 | 43 | end = System.Environment.WorkingSet | |
| 44 | 44 | diff = end - start | |
| 45 | 45 | if diff > 0: | |
| 46 | - diff = '+%d' % diff | ||
| 46 | + diff = '+{0}'.format(diff) | ||
| 47 | 47 | else: | |
| 48 | - diff = '%d' % diff | ||
| 49 | - print(" start: %d end: %d diff: %s" % (start, end, diff)) | ||
| 48 | + diff = '{0}'.format(diff) | ||
| 49 | + print(" start: {0} end: {1} diff: {2}".format(start, end, diff)) | ||
| 50 | 50 | print("") | |
| 51 | 51 | ||
| 52 | 52 | def run(self): | |
@@ -203,10 +203,10 @@ def test_events(self): | |||
| 203 | 203 | testob.PublicEvent -= EventTest.StaticHandler | |
| 204 | 204 | ||
| 205 | 205 | # Function event handler | |
| 206 | - dict = {'value': None} | ||
| 206 | + dict_ = {'value': None} | ||
| 207 | 207 | ||
| 208 | - def handler(sender, args, dict=dict): | ||
| 209 | - dict['value'] = args.value | ||
| 208 | + def handler(sender, args, dict_=dict_): | ||
| 209 | + dict_['value'] = args.value | ||
| 210 | 210 | ||
| 211 | 211 | testob.PublicEvent += handler | |
| 212 | 212 | testob.PublicEvent(testob, TestEventArgs(10)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,12 +26,12 @@ def main(): | |||
| 26 | 26 | start = time.clock() | |
| 27 | 27 | ||
| 28 | 28 | for i in range(50): | |
| 29 | - print('iteration: %d' % i) | ||
| 29 | + print('iteration: {0:d}'.format(i)) | ||
| 30 | 30 | runtests.main() | |
| 31 | 31 | ||
| 32 | 32 | stop = time.clock() | |
| 33 | 33 | took = str(stop - start) | |
| 34 | - print('Total Time: %s' % took) | ||
| 34 | + print('Total Time: {0}'.format(took)) | ||
| 35 | 35 | ||
| 36 | 36 | for item in gc.get_objects(): | |
| 37 | 37 | print(item, sys.getrefcount(item)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,7 +58,7 @@ | |||
| 58 | 58 | def remove_pyc(): | |
| 59 | 59 | path = os.path.dirname(os.path.abspath(__file__)) | |
| 60 | 60 | for name in test_modules: | |
| 61 | - pyc = os.path.join(path, "%s.pyc" % name) | ||
| 61 | + pyc = os.path.join(path, "{0}.pyc".format(name)) | ||
| 62 | 62 | if os.path.isfile(pyc): | |
| 63 | 63 | os.unlink(pyc) | |
| 64 | 64 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,12 +18,7 @@ | |||
| 18 | 18 | import time | |
| 19 | 19 | ||
| 20 | 20 | from _compat import range, thread | |
| 21 | - | ||
| 22 | - | ||
| 23 | - def dprint(msg): | ||
| 24 | - # Debugging helper to trace thread-related tests. | ||
| 25 | - if 1: | ||
| 26 | - print(msg) | ||
| 21 | + from utils import dprint | ||
| 27 | 22 | ||
| 28 | 23 | ||
| 29 | 24 | class StressTest(object): | |
@@ -35,47 +30,47 @@ def __init__(self): | |||
| 35 | 30 | self.module = runtests | |
| 36 | 31 | self.done = [] | |
| 37 | 32 | ||
| 38 | - def markStart(self): | ||
| 33 | + def mark_start(self): | ||
| 39 | 34 | self._start = time.clock() | |
| 40 | 35 | ||
| 41 | - def markFinish(self): | ||
| 36 | + def mark_finish(self): | ||
| 42 | 37 | self._finish = time.clock() | |
| 43 | 38 | ||
| 44 | 39 | def elapsed(self): | |
| 45 | 40 | return self._finish - self._start | |
| 46 | 41 | ||
| 47 | - def printGCReport(self): | ||
| 42 | + def print_gc_report(self): | ||
| 48 | 43 | for item in gc.get_objects(): | |
| 49 | 44 | print(item, sys.getrefcount(item)) | |
| 50 | 45 | ||
| 51 | - def runThread(self, iterations): | ||
| 46 | + def run_thread(self, iterations): | ||
| 52 | 47 | thread_id = thread.get_ident() | |
| 53 | - dprint("thread %s starting..." % thread_id) | ||
| 48 | + dprint("thread {0} starting...".format(thread_id)) | ||
| 54 | 49 | time.sleep(0.1) | |
| 55 | 50 | for i in range(iterations): | |
| 56 | - dprint("thread %s iter %d start" % (thread_id, i)) | ||
| 51 | + dprint("thread {0} iter {1} start".format(thread_id, i)) | ||
| 57 | 52 | self.module.main() | |
| 58 | - dprint("thread %s iter %d end" % (thread_id, i)) | ||
| 53 | + dprint("thread {0} iter {1} end".format(thread_id, i)) | ||
| 59 | 54 | self.done.append(None) | |
| 60 | - dprint("thread %s done" % thread_id) | ||
| 55 | + dprint("thread {0} done".format(thread_id)) | ||
| 61 | 56 | ||
| 62 | - def stressTest(self, iterations=1, threads=1): | ||
| 57 | + def stress_test(self, iterations=1, threads=1): | ||
| 63 | 58 | args = (iterations,) | |
| 64 | - self.markStart() | ||
| 59 | + self.mark_start() | ||
| 65 | 60 | for _ in range(threads): | |
| 66 | - thread = threading.Thread(target=self.runThread, args=args) | ||
| 61 | + thread = threading.Thread(target=self.run_thread, args=args) | ||
| 67 | 62 | thread.start() | |
| 68 | 63 | while len(self.done) < (iterations * threads): | |
| 69 | 64 | dprint(len(self.done)) | |
| 70 | 65 | time.sleep(0.1) | |
| 71 | - self.markFinish() | ||
| 66 | + self.mark_finish() | ||
| 72 | 67 | took = self.elapsed() | |
| 73 | - self.printGCReport() | ||
| 68 | + self.print_gc_report() | ||
| 74 | 69 | ||
| 75 | 70 | ||
| 76 | 71 | def main(): | |
| 77 | 72 | test = StressTest() | |
| 78 | - test.stressTest(2, 10) | ||
| 73 | + test.stress_test(2, 10) | ||
| 79 | 74 | ||
| 80 | 75 | ||
| 81 | 76 | if __name__ == '__main__': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ def main(): | |||
| 50 | 50 | ||
| 51 | 51 | stop = time.clock() | |
| 52 | 52 | took = str(stop - start) | |
| 53 | - print('Total Time: %s' % took) | ||
| 53 | + print('Total Time: {0}'.format(took)) | ||
| 54 | 54 | ||
| 55 | 55 | for i in gc.get_objects(): | |
| 56 | 56 | print(i) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments