python/nondist/sandbox/parrotbench b.py, NONE, 1.1 b3.py, NONE, 1.1 out3, NONE, 1.1 b0.py, 1.2, 1.3

Update of /cvsroot/python/python/nondist/sandbox/parrotbench In directory sc8-pr-cvs1:/tmp/cvs-serv29507 Modified Files: b0.py Added Files: b.py b3.py out3 Log Message: Add driver. Add sorting experiment. --- NEW FILE: b.py --- import b0 import b1 import b2 import b3 --- NEW FILE: b3.py --- class Random: def __init__(self, x, y, z): self._seed = (x, y, z) def random(self): x, y, z = self._seed x = (171 * x) % 30269 y = (172 * y) % 30307 z = (170 * z) % 30323 self._seed = x, y, z return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0 def uniform(self, a, b): return a + (b-a) * self.random() def randint(self, a, b): return a + int((b+1-a) * self.random()) def choice(self, seq): return seq[int(self.random() * len(seq))] rgen = Random(57, 86, 708 % 650) compares = 0 T = int class TT(T): def __repr__(self): return "T(%d)" % self class Int(TT): def __new__(cls, value=None): if value is None: value = rgen.randint(0, 0x7ffffffe) return TT.__new__(cls, value) def icmp(a, b): global compares compares += 1 return T.__cmp__(a, b) N = 20000 K = 1 if __debug__: import time def sortum(data, cmp=None): global compares compares = 0 data = data[:] if __debug__: t0 = time.time() if cmp is None: print "using None" data.sort() else: print "using", cmp.__name__ data.sort(cmp) if __debug__: t1 = time.time() print "Z", data[:K], data[N//2:N//2+K], data[-K:] print compares, if __debug__: print "%.3f" % (t1-t0), print def main(): if __debug__: t0 = time.time() data = [Int() for x in xrange(N)] if __debug__: t1 = time.time() if __debug__: print "%.3f" % (t1-t0) print "A", data[:K], data[N//2:N//2+K], data[-K:] sortum(data) sortum(data, cmp) sortum(data, icmp) TT.__cmp__ = icmp sortum(data) TT.__cmp__ = T.__cmp__ sortum(data) main() --- NEW FILE: out3 --- 0.277 A [T(290448019)] [T(606178844)] [T(186360231)] using None Z [T(387083)] [T(1077158269)] [T(2146971462)] 0 0.013 using cmp Z [T(387083)] [T(1077158269)] [T(2146971462)] 0 0.055 using icmp Z [T(387083)] [T(1077158269)] [T(2146971462)] 119885 0.265 using None Z [T(387083)] [T(1077158269)] [T(2146971462)] 119885 0.331 using None Z [T(387083)] [T(1077158269)] [T(2146971462)] 0 0.025 Index: b0.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/parrotbench/b0.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** b0.py 30 Dec 2003 16:28:25 -0000 1.2 --- b0.py 31 Dec 2003 00:10:34 -0000 1.3 *************** *** 693,697 **** output = OutputFile() def write(s): ! s = str(s) i = s.find(' at 0x') while i > 0: --- 693,697 ---- output = OutputFile() def write(s): ! s = str(s).replace('<b0.', '<__main__.') i = s.find(' at 0x') while i > 0:
participants (1)
-
gvanrossumļ¼ users.sourceforge.net