"""Performance tester for P4Python. Compares a loop executing a simple info command via P4Python and by parsing the p4.exe command line. Assumes you have a p4.exe in your path. """ from p4 import P4 import os, sys, string, marshal class p4g: def __init__(self, port=None, user=None): self.options = '' if not port is None: self.options = " -p " + port if not user is None: self.options += " -u " + user self.mode = 'rb' if os.name != 'nt' : self.mode = 'r' def run(self, command): command = "p4.exe -G " + self.options + " " + command stream = os.popen(command, self.mode) results = [] try: while 1: results.append(marshal.load(stream)) except EOFError: status = stream.close() #if status: #raise "Perforce Error", "exit status %d" % status if (len(results) == 1 and results[0].has_key('code') and results[0]["code"] == "error"): raise "Perforce Error", results[0]["data"] return results def p4g_test(p4): ret = p4.run("-c bruno_ws info") # print ret def p4g_setup(): return p4g("1666", "robert") def p4_test(p4): ret = p4.run("info") # print ret def p4_setup(): p4 = P4() p4.port = "1666" p4.user = "robert" p4.client = "bruno_ws" p4.tagged() p4.connect() return p4 if __name__ == "__main__": repeat_count = 50 from timeit import Timer t = Timer("p4_test(p4)", 'from __main__ import p4_setup, p4_test' + '\n' + 'p4 = p4_setup()') p4time = t.timeit(repeat_count) print "%d repeats using p4.py" % repeat_count, p4time, " avg: %f" % (float(p4time) / repeat_count) t = Timer("p4g_test(p4)", 'from __main__ import p4g_setup, p4g_test' + '\n' + 'p4 = p4g_setup()') p4exetime = t.timeit(repeat_count) print "%d repeats using p4.exe" % repeat_count, p4exetime, " avg: %f" % (float(p4exetime) / repeat_count) print "Ratio: %f" % (p4exetime * 100 / p4time), "%"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 4812 | Robert Cowham |
Made it ready for PyPI (Python Package Index) release and did that. Fixed perf.py script to be compatible with latest changes. |
||
#1 | 4766 | Robert Cowham |
Rather better documentation (and license and changelog). Reorganised dirs. Added .zip file and windows binary installer. |