From 774b972df6a163453518fca5cee55fb101c72754 Mon Sep 17 00:00:00 2001 From: sasha Date: Mon, 25 Apr 2022 21:12:32 +0300 Subject: [PATCH 1/4] Overwrite benchmarks - remove pyperf' shell --- .../data-files/benchmarks/.idea/.gitignore | 8 + .../benchmarks/.idea/benchmarks.iml | 12 + .../inspectionProfiles/profiles_settings.xml | 6 + .../data-files/benchmarks/.idea/misc.xml | 4 + .../data-files/benchmarks/.idea/modules.xml | 8 + .../data-files/benchmarks/.idea/vcs.xml | 6 + .../benchmarks/bm_2to3/test_noperf.py | 35 + .../benchmarks/bm_chameleon/test_noperf.py | 49 + .../benchmarks/bm_chaos/bm_test.pstats | Bin 0 -> 88176 bytes .../benchmarks/bm_chaos/test_noperf.py | 319 +++ .../benchmarks/bm_crypto_pyaes/test_noperf.py | 57 + .../benchmarks/bm_deltablue/test_noperf.py | 659 ++++++ .../bm_django_template/test_noperf.py | 65 + .../benchmarks/bm_dulwich_log/test_noperf.py | 45 + .../benchmarks/bm_fannkuch/test_noperf.py | 83 + .../benchmarks/bm_float/test_noperf.py | 79 + .../benchmarks/bm_genshi/test_noperf.py | 76 + .../benchmarks/bm_go/test_noperf.py | 477 +++++ .../benchmarks/bm_hexiom/test_noperf.py | 671 ++++++ .../benchmarks/bm_hg_startup/test_noperf.py | 56 + .../benchmarks/bm_html5lib/test_noperf.py | 51 + .../benchmarks/bm_json_dumps/test_noperf.py | 74 + .../benchmarks/bm_json_loads/test_noperf.py | 124 ++ .../benchmarks/bm_logging/test_noperf.py | 166 ++ .../benchmarks/bm_mako/test_noperf.py | 159 ++ .../benchmarks/bm_mdp/test_noperf.py | 281 +++ .../bm_meteor_contest/test_noperf.py | 230 +++ .../benchmarks/bm_nbody/test_noperf.py | 165 ++ .../benchmarks/bm_nqueens/test_noperf.py | 80 + .../benchmarks/bm_pathlib/test_noperf.py | 86 + .../benchmarks/bm_pickle/test_noperf.py | 305 +++ .../benchmarks/bm_pidigits/test_noperf.py | 87 + .../benchmarks/bm_pyflate/test_noperf.py | 678 +++++++ .../bm_python_startup/test_noperf.py | 51 + .../benchmarks/bm_raytrace/test_noperf.py | 411 ++++ .../bm_regex_compile/test_noperf.py | 80 + .../benchmarks/bm_regex_dna/test_noperf.py | 240 +++ .../benchmarks/bm_regex_effbot/test_noperf.py | 183 ++ .../benchmarks/bm_regex_v8/test_noperf.py | 1806 +++++++++++++++++ .../benchmarks/bm_richards/test_noperf.py | 441 ++++ .../benchmarks/bm_scimark/.test_noperf.py.swo | Bin 0 -> 16384 bytes .../benchmarks/bm_scimark/test_noperf.py | 425 ++++ .../bm_spectral_norm/test_noperf.py | 84 + .../bm_sqlalchemy_declarative/test_noperf.py | 108 + .../bm_sqlalchemy_imperative/test_noperf.py | 98 + .../benchmarks/bm_sqlite_synth/test_noperf.py | 69 + .../benchmarks/bm_telco/test_noperf.py | 100 + .../benchmarks/bm_tornado_http/test_noperf.py | 116 ++ .../bm_unpack_sequence/test_noperf.py | 465 +++++ .../benchmarks/bm_xml_etree/test_noperf.py | 296 +++ 50 files changed, 10174 insertions(+) create mode 100644 pyperformance/data-files/benchmarks/.idea/.gitignore create mode 100644 pyperformance/data-files/benchmarks/.idea/benchmarks.iml create mode 100644 pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 pyperformance/data-files/benchmarks/.idea/misc.xml create mode 100644 pyperformance/data-files/benchmarks/.idea/modules.xml create mode 100644 pyperformance/data-files/benchmarks/.idea/vcs.xml create mode 100644 pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_chaos/bm_test.pstats create mode 100644 pyperformance/data-files/benchmarks/bm_chaos/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_float/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_go/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_logging/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_mako/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py create mode 100755 pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_richards/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_scimark/.test_noperf.py.swo create mode 100644 pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_telco/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py create mode 100644 pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py diff --git a/pyperformance/data-files/benchmarks/.idea/.gitignore b/pyperformance/data-files/benchmarks/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pyperformance/data-files/benchmarks/.idea/benchmarks.iml b/pyperformance/data-files/benchmarks/.idea/benchmarks.iml new file mode 100644 index 00000000..8b8c3954 --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/benchmarks.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml b/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/misc.xml b/pyperformance/data-files/benchmarks/.idea/misc.xml new file mode 100644 index 00000000..d1e22ecb --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/modules.xml b/pyperformance/data-files/benchmarks/.idea/modules.xml new file mode 100644 index 00000000..799c48d3 --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/vcs.xml b/pyperformance/data-files/benchmarks/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/pyperformance/data-files/benchmarks/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py b/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py new file mode 100644 index 00000000..51613823 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py @@ -0,0 +1,35 @@ +import glob +import os.path +import sys +import subprocess + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + datadir = os.path.join(os.path.dirname(__file__), 'data', '2to3') + pyfiles = glob.glob(os.path.join(datadir, '*.py.txt')) + + command = [sys.executable, "-m", "lib2to3", "-f", "all"] + pyfiles + subprocess.run(command, capture_output=True) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py b/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py new file mode 100644 index 00000000..e69767db --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py @@ -0,0 +1,49 @@ +import functools + + +from chameleon import PageTemplate +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +BIGTABLE_ZPT = """\ + + + + +
+ +
""" + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + tmpl = PageTemplate(BIGTABLE_ZPT) + table = [dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) + for x in range(500)] + options = {'table': table} + + func = functools.partial(tmpl, options=options) + func() + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_chaos/bm_test.pstats b/pyperformance/data-files/benchmarks/bm_chaos/bm_test.pstats new file mode 100644 index 0000000000000000000000000000000000000000..6d5b58a47e8c308a73f99aec4834e51364aeb0f9 GIT binary patch literal 88176 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" % (self.x, self.y, self.z) + + def __repr__(self): + return "GVector(%f, %f, %f)" % (self.x, self.y, self.z) + + +class Spline(object): + """Class for representing B-Splines and NURBS of arbitrary degree""" + + def __init__(self, points, degree, knots): + """Creates a Spline. + + points is a list of GVector, degree is the degree of the Spline. + """ + if len(points) > len(knots) - degree + 1: + raise ValueError("too many control points") + elif len(points) < len(knots) - degree + 1: + raise ValueError("not enough control points") + last = knots[0] + for cur in knots[1:]: + if cur < last: + raise ValueError("knots not strictly increasing") + last = cur + self.knots = knots + self.points = points + self.degree = degree + + def GetDomain(self): + """Returns the domain of the B-Spline""" + return (self.knots[self.degree - 1], + self.knots[len(self.knots) - self.degree]) + + def __call__(self, u): + """Calculates a point of the B-Spline using de Boors Algorithm""" + dom = self.GetDomain() + if u < dom[0] or u > dom[1]: + raise ValueError("Function value not in domain") + if u == dom[0]: + return self.points[0] + if u == dom[1]: + return self.points[-1] + I = self.GetIndex(u) + d = [self.points[I - self.degree + 1 + ii] + for ii in range(self.degree + 1)] + U = self.knots + for ik in range(1, self.degree + 1): + for ii in range(I - self.degree + ik + 1, I + 2): + ua = U[ii + self.degree - ik] + ub = U[ii - 1] + co1 = (ua - u) / (ua - ub) + co2 = (u - ub) / (ua - ub) + index = ii - I + self.degree - ik - 1 + d[index] = d[index].linear_combination(d[index + 1], co1, co2) + return d[0] + + def GetIndex(self, u): + dom = self.GetDomain() + for ii in range(self.degree - 1, len(self.knots) - self.degree): + if u >= self.knots[ii] and u < self.knots[ii + 1]: + I = ii + break + else: + I = dom[1] - 1 + return I + + def __len__(self): + return len(self.points) + + def __repr__(self): + return "Spline(%r, %r, %r)" % (self.points, self.degree, self.knots) + + +def write_ppm(im, filename): + magic = 'P6\n' + maxval = 255 + w = len(im) + h = len(im[0]) + + with open(filename, "w", encoding="latin1", newline='') as fp: + fp.write(magic) + fp.write('%i %i\n%i\n' % (w, h, maxval)) + for j in range(h): + for i in range(w): + val = im[i][j] + c = val * 255 + fp.write('%c%c%c' % (c, c, c)) + + +class Chaosgame(object): + + def __init__(self, splines, thickness=0.1): + self.splines = splines + self.thickness = thickness + self.minx = min([p.x for spl in splines for p in spl.points]) + self.miny = min([p.y for spl in splines for p in spl.points]) + self.maxx = max([p.x for spl in splines for p in spl.points]) + self.maxy = max([p.y for spl in splines for p in spl.points]) + self.height = self.maxy - self.miny + self.width = self.maxx - self.minx + self.num_trafos = [] + maxlength = thickness * self.width / self.height + for spl in splines: + length = 0 + curr = spl(0) + for i in range(1, 1000): + last = curr + t = 1 / 999 * i + curr = spl(t) + length += curr.dist(last) + self.num_trafos.append(max(1, int(length / maxlength * 1.5))) + self.num_total = sum(self.num_trafos) + + def get_random_trafo(self): + r = random.randrange(int(self.num_total) + 1) + l = 0 + for i in range(len(self.num_trafos)): + if r >= l and r < l + self.num_trafos[i]: + return i, random.randrange(self.num_trafos[i]) + l += self.num_trafos[i] + return len(self.num_trafos) - 1, random.randrange(self.num_trafos[-1]) + + def transform_point(self, point, trafo=None): + x = (point.x - self.minx) / self.width + y = (point.y - self.miny) / self.height + if trafo is None: + trafo = self.get_random_trafo() + start, end = self.splines[trafo[0]].GetDomain() + length = end - start + seg_length = length / self.num_trafos[trafo[0]] + t = start + seg_length * trafo[1] + seg_length * x + basepoint = self.splines[trafo[0]](t) + if t + 1 / 50000 > end: + neighbour = self.splines[trafo[0]](t - 1 / 50000) + derivative = neighbour - basepoint + else: + neighbour = self.splines[trafo[0]](t + 1 / 50000) + derivative = basepoint - neighbour + if derivative.Mag() != 0: + basepoint.x += derivative.y / derivative.Mag() * (y - 0.5) * \ + self.thickness + basepoint.y += -derivative.x / derivative.Mag() * (y - 0.5) * \ + self.thickness + else: + print("r", end='') + self.truncate(basepoint) + return basepoint + + def truncate(self, point): + if point.x >= self.maxx: + point.x = self.maxx + if point.y >= self.maxy: + point.y = self.maxy + if point.x < self.minx: + point.x = self.minx + if point.y < self.miny: + point.y = self.miny + + def create_image_chaos(self, w, h, iterations, filename, rng_seed): + # Always use the same sequence of random numbers + # to get reproductible benchmark + random.seed(rng_seed) + + im = [[1] * h for i in range(w)] + point = GVector((self.maxx + self.minx) / 2, + (self.maxy + self.miny) / 2, 0) + for _ in range(iterations): + point = self.transform_point(point) + x = (point.x - self.minx) / self.width * w + y = (point.y - self.miny) / self.height * h + x = int(x) + y = int(y) + if x == w: + x -= 1 + if y == h: + y -= 1 + im[x][h - y - 1] = 0 + + if filename: + write_ppm(im, filename) + + +def run(args): + splines = [ + Spline([ + GVector(1.597350, 3.304460, 0.000000), + GVector(1.575810, 4.123260, 0.000000), + GVector(1.313210, 5.288350, 0.000000), + GVector(1.618900, 5.329910, 0.000000), + GVector(2.889940, 5.502700, 0.000000), + GVector(2.373060, 4.381830, 0.000000), + GVector(1.662000, 4.360280, 0.000000)], + 3, [0, 0, 0, 1, 1, 1, 2, 2, 2]), + Spline([ + GVector(2.804500, 4.017350, 0.000000), + GVector(2.550500, 3.525230, 0.000000), + GVector(1.979010, 2.620360, 0.000000), + GVector(1.979010, 2.620360, 0.000000)], + 3, [0, 0, 0, 1, 1, 1]), + Spline([ + GVector(2.001670, 4.011320, 0.000000), + GVector(2.335040, 3.312830, 0.000000), + GVector(2.366800, 3.233460, 0.000000), + GVector(2.366800, 3.233460, 0.000000)], + 3, [0, 0, 0, 1, 1, 1]) + ] + + chaos = Chaosgame(splines, args.thickness) + chaos.create_image_chaos(args.width, args.height, + args.iterations, args.filename, args.rng_seed) + + +def add_cmdline_args(cmd, args): + cmd.append("--width=%s" % args.width) + cmd.append("--height=%s" % args.height) + cmd.append("--thickness=%s" % args.thickness) + cmd.append("--rng-seed=%s" % args.rng_seed) + if args.filename: + cmd.extend(("--filename", args.filename)) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--thickness", + type=float, default=DEFAULT_THICKNESS, + help="Thickness (default: %s)" % DEFAULT_THICKNESS) + parser.add_argument("--width", + type=int, default=DEFAULT_WIDTH, + help="Image width (default: %s)" % DEFAULT_WIDTH) + parser.add_argument("--height", + type=int, default=DEFAULT_HEIGHT, + help="Image height (default: %s)" % DEFAULT_HEIGHT) + parser.add_argument("--iterations", + type=int, default=DEFAULT_ITERATIONS, + help="Number of iterations (default: %s)" + % DEFAULT_ITERATIONS) + parser.add_argument("--filename", metavar="FILENAME.PPM", + help="Output filename of the PPM picture") + parser.add_argument("--rng-seed", + type=int, default=DEFAULT_RNG_SEED, + help="Random number generator seed (default: %s)" + % DEFAULT_RNG_SEED) + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + run(args) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py b/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py new file mode 100644 index 00000000..01dcad3d --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +""" +Pure-Python Implementation of the AES block-cipher. + +Benchmark AES in CTR mode using the pyaes module. +""" + +import pyaes + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# 23,000 bytes +CLEARTEXT = b"This is a test. What could possibly go wrong? " * 500 + +# 128-bit key (16 bytes) +KEY = b'\xa1\xf6%\x8c\x87}_\xcd\x89dHE8\xbf\xc9,' + + +def bench_pyaes(): + aes = pyaes.AESModeOfOperationCTR(KEY) + ciphertext = aes.encrypt(CLEARTEXT) + + # need to reset IV for decryption + aes = pyaes.AESModeOfOperationCTR(KEY) + plaintext = aes.decrypt(ciphertext) + + # explicitly destroy the pyaes object + aes = None + + if plaintext != CLEARTEXT: + raise Exception("decrypt error!") + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_pyaes() + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py b/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py new file mode 100644 index 00000000..90e1dc78 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py @@ -0,0 +1,659 @@ +""" +deltablue.py +============ + +Ported for the PyPy project. +Contributed by Daniel Lindsley + +This implementation of the DeltaBlue benchmark was directly ported +from the `V8's source code`_, which was in turn derived +from the Smalltalk implementation by John Maloney and Mario +Wolczko. The original Javascript implementation was licensed under the GPL. + +It's been updated in places to be more idiomatic to Python (for loops over +collections, a couple magic methods, ``OrderedCollection`` being a list & things +altering those collections changed to the builtin methods) but largely retains +the layout & logic from the original. (Ugh.) + +.. _`V8's source code`: (https://github.com/v8/v8/blob/master/benchmarks/deltablue.js) +""" + +from cProfile import Profile + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# The JS variant implements "OrderedCollection", which basically completely +# overlaps with ``list``. So we'll cheat. :D +class OrderedCollection(list): + pass + + +class Strength(object): + REQUIRED = None + STRONG_PREFERRED = None + PREFERRED = None + STRONG_DEFAULT = None + NORMAL = None + WEAK_DEFAULT = None + WEAKEST = None + + def __init__(self, strength, name): + super(Strength, self).__init__() + self.strength = strength + self.name = name + + @classmethod + def stronger(cls, s1, s2): + return s1.strength < s2.strength + + @classmethod + def weaker(cls, s1, s2): + return s1.strength > s2.strength + + @classmethod + def weakest_of(cls, s1, s2): + if cls.weaker(s1, s2): + return s1 + + return s2 + + @classmethod + def strongest(cls, s1, s2): + if cls.stronger(s1, s2): + return s1 + + return s2 + + def next_weaker(self): + strengths = { + 0: self.__class__.WEAKEST, + 1: self.__class__.WEAK_DEFAULT, + 2: self.__class__.NORMAL, + 3: self.__class__.STRONG_DEFAULT, + 4: self.__class__.PREFERRED, + # TODO: This looks like a bug in the original code. Shouldn't this be + # ``STRONG_PREFERRED? Keeping for porting sake... + 5: self.__class__.REQUIRED, + } + return strengths[self.strength] + + +# This is a terrible pattern IMO, but true to the original JS implementation. +Strength.REQUIRED = Strength(0, "required") +Strength.STRONG_PREFERRED = Strength(1, "strongPreferred") +Strength.PREFERRED = Strength(2, "preferred") +Strength.STRONG_DEFAULT = Strength(3, "strongDefault") +Strength.NORMAL = Strength(4, "normal") +Strength.WEAK_DEFAULT = Strength(5, "weakDefault") +Strength.WEAKEST = Strength(6, "weakest") + + +class Constraint(object): + + def __init__(self, strength): + super(Constraint, self).__init__() + self.strength = strength + + def add_constraint(self): + global planner + self.add_to_graph() + planner.incremental_add(self) + + def satisfy(self, mark): + global planner + self.choose_method(mark) + + if not self.is_satisfied(): + if self.strength == Strength.REQUIRED: + print('Could not satisfy a required constraint!') + + return None + + self.mark_inputs(mark) + out = self.output() + overridden = out.determined_by + + if overridden is not None: + overridden.mark_unsatisfied() + + out.determined_by = self + + if not planner.add_propagate(self, mark): + print('Cycle encountered') + + out.mark = mark + return overridden + + def destroy_constraint(self): + global planner + if self.is_satisfied(): + planner.incremental_remove(self) + else: + self.remove_from_graph() + + def is_input(self): + return False + + +class UrnaryConstraint(Constraint): + + def __init__(self, v, strength): + super(UrnaryConstraint, self).__init__(strength) + self.my_output = v + self.satisfied = False + self.add_constraint() + + def add_to_graph(self): + self.my_output.add_constraint(self) + self.satisfied = False + + def choose_method(self, mark): + if self.my_output.mark != mark and \ + Strength.stronger(self.strength, self.my_output.walk_strength): + self.satisfied = True + else: + self.satisfied = False + + def is_satisfied(self): + return self.satisfied + + def mark_inputs(self, mark): + # No-ops. + pass + + def output(self): + # Ugh. Keeping it for consistency with the original. So much for + # "we're all adults here"... + return self.my_output + + def recalculate(self): + self.my_output.walk_strength = self.strength + self.my_output.stay = not self.is_input() + + if self.my_output.stay: + self.execute() + + def mark_unsatisfied(self): + self.satisfied = False + + def inputs_known(self, mark): + return True + + def remove_from_graph(self): + if self.my_output is not None: + self.my_output.remove_constraint(self) + self.satisfied = False + + +class StayConstraint(UrnaryConstraint): + + def __init__(self, v, string): + super(StayConstraint, self).__init__(v, string) + + def execute(self): + # The methods, THEY DO NOTHING. + pass + + +class EditConstraint(UrnaryConstraint): + + def __init__(self, v, string): + super(EditConstraint, self).__init__(v, string) + + def is_input(self): + return True + + def execute(self): + # This constraint also does nothing. + pass + + +class Direction(object): + # Hooray for things that ought to be structs! + NONE = 0 + FORWARD = 1 + BACKWARD = -1 + + +class BinaryConstraint(Constraint): + + def __init__(self, v1, v2, strength): + super(BinaryConstraint, self).__init__(strength) + self.v1 = v1 + self.v2 = v2 + self.direction = Direction.NONE + self.add_constraint() + + def choose_method(self, mark): + if self.v1.mark == mark: + if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): + self.direction = Direction.FORWARD + else: + self.direction = Direction.BACKWARD + + if self.v2.mark == mark: + if self.v1.mark != mark and Strength.stronger(self.strength, self.v1.walk_strength): + self.direction = Direction.BACKWARD + else: + self.direction = Direction.NONE + + if Strength.weaker(self.v1.walk_strength, self.v2.walk_strength): + if Strength.stronger(self.strength, self.v1.walk_strength): + self.direction = Direction.BACKWARD + else: + self.direction = Direction.NONE + else: + if Strength.stronger(self.strength, self.v2.walk_strength): + self.direction = Direction.FORWARD + else: + self.direction = Direction.BACKWARD + + def add_to_graph(self): + self.v1.add_constraint(self) + self.v2.add_constraint(self) + self.direction = Direction.NONE + + def is_satisfied(self): + return self.direction != Direction.NONE + + def mark_inputs(self, mark): + self.input().mark = mark + + def input(self): + if self.direction == Direction.FORWARD: + return self.v1 + + return self.v2 + + def output(self): + if self.direction == Direction.FORWARD: + return self.v2 + + return self.v1 + + def recalculate(self): + ihn = self.input() + out = self.output() + out.walk_strength = Strength.weakest_of( + self.strength, ihn.walk_strength) + out.stay = ihn.stay + + if out.stay: + self.execute() + + def mark_unsatisfied(self): + self.direction = Direction.NONE + + def inputs_known(self, mark): + i = self.input() + return i.mark == mark or i.stay or i.determined_by is None + + def remove_from_graph(self): + if self.v1 is not None: + self.v1.remove_constraint(self) + + if self.v2 is not None: + self.v2.remove_constraint(self) + + self.direction = Direction.NONE + + +class ScaleConstraint(BinaryConstraint): + + def __init__(self, src, scale, offset, dest, strength): + self.direction = Direction.NONE + self.scale = scale + self.offset = offset + super(ScaleConstraint, self).__init__(src, dest, strength) + + def add_to_graph(self): + super(ScaleConstraint, self).add_to_graph() + self.scale.add_constraint(self) + self.offset.add_constraint(self) + + def remove_from_graph(self): + super(ScaleConstraint, self).remove_from_graph() + + if self.scale is not None: + self.scale.remove_constraint(self) + + if self.offset is not None: + self.offset.remove_constraint(self) + + def mark_inputs(self, mark): + super(ScaleConstraint, self).mark_inputs(mark) + self.scale.mark = mark + self.offset.mark = mark + + def execute(self): + if self.direction == Direction.FORWARD: + self.v2.value = self.v1.value * self.scale.value + self.offset.value + else: + self.v1.value = ( + self.v2.value - self.offset.value) / self.scale.value + + def recalculate(self): + ihn = self.input() + out = self.output() + out.walk_strength = Strength.weakest_of( + self.strength, ihn.walk_strength) + out.stay = ihn.stay and self.scale.stay and self.offset.stay + + if out.stay: + self.execute() + + +class EqualityConstraint(BinaryConstraint): + + def execute(self): + self.output().value = self.input().value + + +class Variable(object): + + def __init__(self, name, initial_value=0): + super(Variable, self).__init__() + self.name = name + self.value = initial_value + self.constraints = OrderedCollection() + self.determined_by = None + self.mark = 0 + self.walk_strength = Strength.WEAKEST + self.stay = True + + def __repr__(self): + # To make debugging this beast from pdb easier... + return '' % ( + self.name, + self.value + ) + + def add_constraint(self, constraint): + self.constraints.append(constraint) + + def remove_constraint(self, constraint): + self.constraints.remove(constraint) + + if self.determined_by == constraint: + self.determined_by = None + + +class Planner(object): + + def __init__(self): + super(Planner, self).__init__() + self.current_mark = 0 + + def incremental_add(self, constraint): + mark = self.new_mark() + overridden = constraint.satisfy(mark) + + while overridden is not None: + overridden = overridden.satisfy(mark) + + def incremental_remove(self, constraint): + out = constraint.output() + constraint.mark_unsatisfied() + constraint.remove_from_graph() + unsatisfied = self.remove_propagate_from(out) + strength = Strength.REQUIRED + # Do-while, the Python way. + repeat = True + + while repeat: + for u in unsatisfied: + if u.strength == strength: + self.incremental_add(u) + + strength = strength.next_weaker() + + repeat = strength != Strength.WEAKEST + + def new_mark(self): + self.current_mark += 1 + return self.current_mark + + def make_plan(self, sources): + mark = self.new_mark() + plan = Plan() + todo = sources + + while len(todo): + c = todo.pop(0) + + if c.output().mark != mark and c.inputs_known(mark): + plan.add_constraint(c) + c.output().mark = mark + self.add_constraints_consuming_to(c.output(), todo) + + return plan + + def extract_plan_from_constraints(self, constraints): + sources = OrderedCollection() + + for c in constraints: + if c.is_input() and c.is_satisfied(): + sources.append(c) + + return self.make_plan(sources) + + def add_propagate(self, c, mark): + todo = OrderedCollection() + todo.append(c) + + while len(todo): + d = todo.pop(0) + + if d.output().mark == mark: + self.incremental_remove(c) + return False + + d.recalculate() + self.add_constraints_consuming_to(d.output(), todo) + + return True + + def remove_propagate_from(self, out): + out.determined_by = None + out.walk_strength = Strength.WEAKEST + out.stay = True + unsatisfied = OrderedCollection() + todo = OrderedCollection() + todo.append(out) + + while len(todo): + v = todo.pop(0) + + for c in v.constraints: + if not c.is_satisfied(): + unsatisfied.append(c) + + determining = v.determined_by + + for c in v.constraints: + if c != determining and c.is_satisfied(): + c.recalculate() + todo.append(c.output()) + + return unsatisfied + + def add_constraints_consuming_to(self, v, coll): + determining = v.determined_by + cc = v.constraints + + for c in cc: + if c != determining and c.is_satisfied(): + # I guess we're just updating a reference (``coll``)? Seems + # inconsistent with the rest of the implementation, where they + # return the lists... + coll.append(c) + + +class Plan(object): + + def __init__(self): + super(Plan, self).__init__() + self.v = OrderedCollection() + + def add_constraint(self, c): + self.v.append(c) + + def __len__(self): + return len(self.v) + + def __getitem__(self, index): + return self.v[index] + + def execute(self): + for c in self.v: + c.execute() + + +# Main + +def chain_test(n): + """ + This is the standard DeltaBlue benchmark. A long chain of equality + constraints is constructed with a stay constraint on one end. An + edit constraint is then added to the opposite end and the time is + measured for adding and removing this constraint, and extracting + and executing a constraint satisfaction plan. There are two cases. + In case 1, the added constraint is stronger than the stay + constraint and values must propagate down the entire length of the + chain. In case 2, the added constraint is weaker than the stay + constraint so it cannot be accomodated. The cost in this case is, + of course, very low. Typical situations lie somewhere between these + two extremes. + """ + global planner + planner = Planner() + prev, first, last = None, None, None + + # We need to go up to n inclusively. + for i in range(n + 1): + name = "v%s" % i + v = Variable(name) + + if prev is not None: + EqualityConstraint(prev, v, Strength.REQUIRED) + + if i == 0: + first = v + + if i == n: + last = v + + prev = v + + StayConstraint(last, Strength.STRONG_DEFAULT) + edit = EditConstraint(first, Strength.PREFERRED) + edits = OrderedCollection() + edits.append(edit) + plan = planner.extract_plan_from_constraints(edits) + + for i in range(100): + first.value = i + plan.execute() + + if last.value != i: + print("Chain test failed.") + + +def projection_test(n): + """ + This test constructs a two sets of variables related to each + other by a simple linear transformation (scale and offset). The + time is measured to change a variable on either side of the + mapping and to change the scale and offset factors. + """ + global planner + planner = Planner() + scale = Variable("scale", 10) + offset = Variable("offset", 1000) + src = None + + dests = OrderedCollection() + + for i in range(n): + src = Variable("src%s" % i, i) + dst = Variable("dst%s" % i, i) + dests.append(dst) + StayConstraint(src, Strength.NORMAL) + ScaleConstraint(src, scale, offset, dst, Strength.REQUIRED) + + change(src, 17) + + if dst.value != 1170: + print("Projection 1 failed") + + change(dst, 1050) + + if src.value != 5: + print("Projection 2 failed") + + change(scale, 5) + + for i in range(n - 1): + if dests[i].value != (i * 5 + 1000): + print("Projection 3 failed") + + change(offset, 2000) + + for i in range(n - 1): + if dests[i].value != (i * 5 + 2000): + print("Projection 4 failed") + + +def change(v, new_value): + global planner + edit = EditConstraint(v, Strength.PREFERRED) + edits = OrderedCollection() + edits.append(edit) + + plan = planner.extract_plan_from_constraints(edits) + + for i in range(10): + v.value = new_value + plan.execute() + + edit.destroy_constraint() + + +# HOORAY FOR GLOBALS... Oh wait. +# In spirit of the original, we'll keep it, but ugh. +planner = None + + +def delta_blue(n): + chain_test(n) + projection_test(n) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + n = 100 + delta_blue(n) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + + diff --git a/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py b/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py new file mode 100644 index 00000000..c0fdacb2 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py @@ -0,0 +1,65 @@ +"""Test the performance of the Django template system. + +This will have Django generate a 150x150-cell HTML table. +""" + +import pyperf + +import django.conf +from django.template import Context, Template +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# 2016-10-10: Python 3.6 takes 380 ms +DEFAULT_SIZE = 100 + + +def bench_django_template(size): + template = Template(""" +{% for row in table %} +{% for col in row %}{% endfor %} +{% endfor %} +
{{ col|escape }}
+ """) + table = [range(size) for _ in range(size)] + context = Context({"table": table}) + + template.render(context) + + +def prepare_cmd(runner, cmd): + cmd.append("--table-size=%s" % runner.args.table_size) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--table-size", + type=int, default=DEFAULT_SIZE, + help="Size of the HTML table, height and width " + "(default: %s)" % DEFAULT_SIZE) + args = parser.parse_args() + profiler = Profile(builtins=args.builtins) + profiler.enable() + + django.conf.settings.configure(TEMPLATES=[{ + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + }]) + django.setup() + + bench_django_template(args.table_size) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py b/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py new file mode 100644 index 00000000..5c7e857d --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py @@ -0,0 +1,45 @@ +""" +Iterate on commits of the asyncio Git repository using the Dulwich module. +""" + +import os + +import dulwich.repo + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +def iter_all_commits(repo): + # iterate on all changes on the Git repository + for entry in repo.get_walker(): + pass + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + repo_path = os.path.join(os.path.dirname(__file__), 'data', 'asyncio.git') + repo = dulwich.repo.Repo(repo_path) + head = repo.head() + iter_all_commits(repo) + repo.close() + + profiler.disable() + profiler.dump_stats("test.prof") + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py b/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py new file mode 100644 index 00000000..10193bc8 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py @@ -0,0 +1,83 @@ +""" +The Computer Language Benchmarks Game +http://benchmarksgame.alioth.debian.org/ + +Contributed by Sokolov Yura, modified by Tupteq. +""" + + + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DEFAULT_ARG = 9 + + +def fannkuch(n): + count = list(range(1, n + 1)) + max_flips = 0 + m = n - 1 + r = n + check = 0 + perm1 = list(range(n)) + perm = list(range(n)) + perm1_ins = perm1.insert + perm1_pop = perm1.pop + + while 1: + if check < 30: + check += 1 + + while r != 1: + count[r - 1] = r + r -= 1 + + if perm1[0] != 0 and perm1[m] != m: + perm = perm1[:] + flips_count = 0 + k = perm[0] + while k: + perm[:k + 1] = perm[k::-1] + flips_count += 1 + k = perm[0] + + if flips_count > max_flips: + max_flips = flips_count + + while r != n: + perm1_ins(r, perm1_pop(0)) + count[r] -= 1 + if count[r] > 0: + break + r += 1 + else: + return max_flips + + +def main(): + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + arg = DEFAULT_ARG + fannkuch(arg) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + +if __name__ == "__main__": + main() diff --git a/pyperformance/data-files/benchmarks/bm_float/test_noperf.py b/pyperformance/data-files/benchmarks/bm_float/test_noperf.py new file mode 100644 index 00000000..914ed639 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_float/test_noperf.py @@ -0,0 +1,79 @@ +""" +Artificial, floating point-heavy benchmark originally used by Factor. +""" + +from math import sin, cos, sqrt +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +POINTS = 100000 + + +class Point(object): + __slots__ = ('x', 'y', 'z') + + def __init__(self, i): + self.x = x = sin(i) + self.y = cos(i) * 3 + self.z = (x * x) / 2 + + def __repr__(self): + return "" % (self.x, self.y, self.z) + + def normalize(self): + x = self.x + y = self.y + z = self.z + norm = sqrt(x * x + y * y + z * z) + self.x /= norm + self.y /= norm + self.z /= norm + + def maximize(self, other): + self.x = self.x if self.x > other.x else other.x + self.y = self.y if self.y > other.y else other.y + self.z = self.z if self.z > other.z else other.z + return self + + +def maximize(points): + next = points[0] + for p in points[1:]: + next = next.maximize(p) + return next + + +def benchmark(n): + points = [None] * n + for i in range(n): + points[i] = Point(i) + for p in points: + p.normalize() + return maximize(points) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + points = POINTS + benchmark(points) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py b/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py new file mode 100644 index 00000000..91249f8b --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py @@ -0,0 +1,76 @@ +""" +Render a template using Genshi module. +""" + +from genshi.template import MarkupTemplate, NewTextTemplate +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + + +BIGTABLE_XML = """\ + + + +
+
+""" + +BIGTABLE_TEXT = """\ + +{% for row in table %} +{% for c in row.values() %}{% end %} +{% end %} +
$c
+""" + + +def bench_genshi(tmpl_cls, tmpl_str): + tmpl = tmpl_cls(tmpl_str) + table = [dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) + for _ in range(1000)] + + stream = tmpl.generate(table=table) + stream.render() + + +BENCHMARKS = { + 'xml': (MarkupTemplate, BIGTABLE_XML), + 'text': (NewTextTemplate, BIGTABLE_TEXT), +} + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + parser.add_argument("benchmark", nargs='?', + choices=sorted(BENCHMARKS)) + + args = parser.parse_args() + if args.benchmark: + benchmarks = (args.benchmark,) + else: + benchmarks = sorted(BENCHMARKS) + + for bench in benchmarks: + name = 'genshi_%s' % bench + tmpl_cls, tmpl_str = BENCHMARKS[bench] + bench_genshi(tmpl_cls, tmpl_str) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_go/test_noperf.py b/pyperformance/data-files/benchmarks/bm_go/test_noperf.py new file mode 100644 index 00000000..b40fd2e7 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_go/test_noperf.py @@ -0,0 +1,477 @@ +""" +Go board game +""" +import math +import random + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +SIZE = 9 +GAMES = 200 +KOMI = 7.5 +EMPTY, WHITE, BLACK = 0, 1, 2 +SHOW = {EMPTY: '.', WHITE: 'o', BLACK: 'x'} +PASS = -1 +MAXMOVES = SIZE * SIZE * 3 +TIMESTAMP = 0 +MOVES = 0 + + +def to_pos(x, y): + return y * SIZE + x + + +def to_xy(pos): + y, x = divmod(pos, SIZE) + return x, y + + +class Square: + + def __init__(self, board, pos): + self.board = board + self.pos = pos + self.timestamp = TIMESTAMP + self.removestamp = TIMESTAMP + self.zobrist_strings = [random.randrange(9223372036854775807) + for i in range(3)] + + def set_neighbours(self): + x, y = self.pos % SIZE, self.pos // SIZE + self.neighbours = [] + for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: + newx, newy = x + dx, y + dy + if 0 <= newx < SIZE and 0 <= newy < SIZE: + self.neighbours.append(self.board.squares[to_pos(newx, newy)]) + + def move(self, color): + global TIMESTAMP, MOVES + TIMESTAMP += 1 + MOVES += 1 + self.board.zobrist.update(self, color) + self.color = color + self.reference = self + self.ledges = 0 + self.used = True + for neighbour in self.neighbours: + neighcolor = neighbour.color + if neighcolor == EMPTY: + self.ledges += 1 + else: + neighbour_ref = neighbour.find(update=True) + if neighcolor == color: + if neighbour_ref.reference.pos != self.pos: + self.ledges += neighbour_ref.ledges + neighbour_ref.reference = self + self.ledges -= 1 + else: + neighbour_ref.ledges -= 1 + if neighbour_ref.ledges == 0: + neighbour.remove(neighbour_ref) + self.board.zobrist.add() + + def remove(self, reference, update=True): + self.board.zobrist.update(self, EMPTY) + self.removestamp = TIMESTAMP + if update: + self.color = EMPTY + self.board.emptyset.add(self.pos) +# if color == BLACK: +# self.board.black_dead += 1 +# else: +# self.board.white_dead += 1 + for neighbour in self.neighbours: + if neighbour.color != EMPTY and neighbour.removestamp != TIMESTAMP: + neighbour_ref = neighbour.find(update) + if neighbour_ref.pos == reference.pos: + neighbour.remove(reference, update) + else: + if update: + neighbour_ref.ledges += 1 + + def find(self, update=False): + reference = self.reference + if reference.pos != self.pos: + reference = reference.find(update) + if update: + self.reference = reference + return reference + + def __repr__(self): + return repr(to_xy(self.pos)) + + +class EmptySet: + + def __init__(self, board): + self.board = board + self.empties = list(range(SIZE * SIZE)) + self.empty_pos = list(range(SIZE * SIZE)) + + def random_choice(self): + choices = len(self.empties) + while choices: + i = int(random.random() * choices) + pos = self.empties[i] + if self.board.useful(pos): + return pos + choices -= 1 + self.set(i, self.empties[choices]) + self.set(choices, pos) + return PASS + + def add(self, pos): + self.empty_pos[pos] = len(self.empties) + self.empties.append(pos) + + def remove(self, pos): + self.set(self.empty_pos[pos], self.empties[len(self.empties) - 1]) + self.empties.pop() + + def set(self, i, pos): + self.empties[i] = pos + self.empty_pos[pos] = i + + +class ZobristHash: + + def __init__(self, board): + self.board = board + self.hash_set = set() + self.hash = 0 + for square in self.board.squares: + self.hash ^= square.zobrist_strings[EMPTY] + self.hash_set.clear() + self.hash_set.add(self.hash) + + def update(self, square, color): + self.hash ^= square.zobrist_strings[square.color] + self.hash ^= square.zobrist_strings[color] + + def add(self): + self.hash_set.add(self.hash) + + def dupe(self): + return self.hash in self.hash_set + + +class Board: + + def __init__(self): + self.squares = [Square(self, pos) for pos in range(SIZE * SIZE)] + for square in self.squares: + square.set_neighbours() + self.reset() + + def reset(self): + for square in self.squares: + square.color = EMPTY + square.used = False + self.emptyset = EmptySet(self) + self.zobrist = ZobristHash(self) + self.color = BLACK + self.finished = False + self.lastmove = -2 + self.history = [] + self.white_dead = 0 + self.black_dead = 0 + + def move(self, pos): + square = self.squares[pos] + if pos != PASS: + square.move(self.color) + self.emptyset.remove(square.pos) + elif self.lastmove == PASS: + self.finished = True + if self.color == BLACK: + self.color = WHITE + else: + self.color = BLACK + self.lastmove = pos + self.history.append(pos) + + def random_move(self): + return self.emptyset.random_choice() + + def useful_fast(self, square): + if not square.used: + for neighbour in square.neighbours: + if neighbour.color == EMPTY: + return True + return False + + def useful(self, pos): + global TIMESTAMP + TIMESTAMP += 1 + square = self.squares[pos] + if self.useful_fast(square): + return True + old_hash = self.zobrist.hash + self.zobrist.update(square, self.color) + empties = opps = weak_opps = neighs = weak_neighs = 0 + for neighbour in square.neighbours: + neighcolor = neighbour.color + if neighcolor == EMPTY: + empties += 1 + continue + neighbour_ref = neighbour.find() + if neighbour_ref.timestamp != TIMESTAMP: + if neighcolor == self.color: + neighs += 1 + else: + opps += 1 + neighbour_ref.timestamp = TIMESTAMP + neighbour_ref.temp_ledges = neighbour_ref.ledges + neighbour_ref.temp_ledges -= 1 + if neighbour_ref.temp_ledges == 0: + if neighcolor == self.color: + weak_neighs += 1 + else: + weak_opps += 1 + neighbour_ref.remove(neighbour_ref, update=False) + dupe = self.zobrist.dupe() + self.zobrist.hash = old_hash + strong_neighs = neighs - weak_neighs + strong_opps = opps - weak_opps + return not dupe and \ + (empties or weak_opps or (strong_neighs and (strong_opps or weak_neighs))) + + def useful_moves(self): + return [pos for pos in self.emptyset.empties if self.useful(pos)] + + def replay(self, history): + for pos in history: + self.move(pos) + + def score(self, color): + if color == WHITE: + count = KOMI + self.black_dead + else: + count = self.white_dead + for square in self.squares: + squarecolor = square.color + if squarecolor == color: + count += 1 + elif squarecolor == EMPTY: + surround = 0 + for neighbour in square.neighbours: + if neighbour.color == color: + surround += 1 + if surround == len(square.neighbours): + count += 1 + return count + + def check(self): + for square in self.squares: + if square.color == EMPTY: + continue + + members1 = set([square]) + changed = True + while changed: + changed = False + for member in members1.copy(): + for neighbour in member.neighbours: + if neighbour.color == square.color and neighbour not in members1: + changed = True + members1.add(neighbour) + ledges1 = 0 + for member in members1: + for neighbour in member.neighbours: + if neighbour.color == EMPTY: + ledges1 += 1 + + root = square.find() + + # print 'members1', square, root, members1 + # print 'ledges1', square, ledges1 + + members2 = set() + for square2 in self.squares: + if square2.color != EMPTY and square2.find() == root: + members2.add(square2) + + ledges2 = root.ledges + # print 'members2', square, root, members1 + # print 'ledges2', square, ledges2 + + assert members1 == members2 + assert ledges1 == ledges2, ('ledges differ at %r: %d %d' % ( + square, ledges1, ledges2)) + + set(self.emptyset.empties) + + empties2 = set() + for square in self.squares: + if square.color == EMPTY: + empties2.add(square.pos) + + def __repr__(self): + result = [] + for y in range(SIZE): + start = to_pos(0, y) + result.append(''.join( + [SHOW[square.color] + ' ' for square in self.squares[start:start + SIZE]])) + return '\n'.join(result) + + +class UCTNode: + + def __init__(self): + self.bestchild = None + self.pos = -1 + self.wins = 0 + self.losses = 0 + self.pos_child = [None for x in range(SIZE * SIZE)] + self.parent = None + + def play(self, board): + """ uct tree search """ + color = board.color + node = self + path = [node] + while True: + pos = node.select(board) + if pos == PASS: + break + board.move(pos) + child = node.pos_child[pos] + if not child: + child = node.pos_child[pos] = UCTNode() + child.unexplored = board.useful_moves() + child.pos = pos + child.parent = node + path.append(child) + break + path.append(child) + node = child + self.random_playout(board) + self.update_path(board, color, path) + + def select(self, board): + """ select move; unexplored children first, then according to uct value """ + if self.unexplored: + i = random.randrange(len(self.unexplored)) + pos = self.unexplored[i] + self.unexplored[i] = self.unexplored[len(self.unexplored) - 1] + self.unexplored.pop() + return pos + elif self.bestchild: + return self.bestchild.pos + else: + return PASS + + def random_playout(self, board): + """ random play until both players pass """ + for x in range(MAXMOVES): # XXX while not self.finished? + if board.finished: + break + board.move(board.random_move()) + + def update_path(self, board, color, path): + """ update win/loss count along path """ + wins = board.score(BLACK) >= board.score(WHITE) + for node in path: + if color == BLACK: + color = WHITE + else: + color = BLACK + if wins == (color == BLACK): + node.wins += 1 + else: + node.losses += 1 + if node.parent: + node.parent.bestchild = node.parent.best_child() + + def score(self): + winrate = self.wins / float(self.wins + self.losses) + parentvisits = self.parent.wins + self.parent.losses + if not parentvisits: + return winrate + nodevisits = self.wins + self.losses + return winrate + math.sqrt((math.log(parentvisits)) / (5 * nodevisits)) + + def best_child(self): + maxscore = -1 + maxchild = None + for child in self.pos_child: + if child and child.score() > maxscore: + maxchild = child + maxscore = child.score() + return maxchild + + def best_visited(self): + maxvisits = -1 + maxchild = None + for child in self.pos_child: + # if child: + # print to_xy(child.pos), child.wins, child.losses, child.score() + if child and (child.wins + child.losses) > maxvisits: + maxvisits, maxchild = (child.wins + child.losses), child + return maxchild + + +# def user_move(board): +# while True: +# text = input('?').strip() +# if text == 'p': +# return PASS +# if text == 'q': +# raise EOFError +# try: +# x, y = [int(i) for i in text.split()] +# except ValueError: +# continue +# if not (0 <= x < SIZE and 0 <= y < SIZE): +# continue +# pos = to_pos(x, y) +# if board.useful(pos): +# return pos + + +def computer_move(board): + pos = board.random_move() + if pos == PASS: + return PASS + tree = UCTNode() + tree.unexplored = board.useful_moves() + nboard = Board() + for game in range(GAMES): + node = tree + nboard.reset() + nboard.replay(board.history) + node.play(nboard) + return tree.best_visited().pos + + +def versus_cpu(): + random.seed(1) + board = Board() + return computer_move(board) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + versus_cpu() + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py b/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py new file mode 100644 index 00000000..ead97374 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py @@ -0,0 +1,671 @@ +""" +Solver of Hexiom board game. + +Benchmark from Laurent Vaucher. + +Source: https://github.com/slowfrog/hexiom : hexiom2.py, level36.txt + +(Main function tweaked by Armin Rigo.) +""" + +import io + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# 2016-07-07: CPython 3.6 takes ~25 ms to solve the board level 25 +DEFAULT_LEVEL = 25 + + +################################## +class Dir(object): + + def __init__(self, x, y): + self.x = x + self.y = y + + +DIRS = [Dir(1, 0), + Dir(-1, 0), + Dir(0, 1), + Dir(0, -1), + Dir(1, 1), + Dir(-1, -1)] + +EMPTY = 7 + +################################## + + +class Done(object): + MIN_CHOICE_STRATEGY = 0 + MAX_CHOICE_STRATEGY = 1 + HIGHEST_VALUE_STRATEGY = 2 + FIRST_STRATEGY = 3 + MAX_NEIGHBORS_STRATEGY = 4 + MIN_NEIGHBORS_STRATEGY = 5 + + def __init__(self, count, empty=False): + self.count = count + self.cells = None if empty else [ + [0, 1, 2, 3, 4, 5, 6, EMPTY] for i in range(count)] + + def clone(self): + ret = Done(self.count, True) + ret.cells = [self.cells[i][:] for i in range(self.count)] + return ret + + def __getitem__(self, i): + return self.cells[i] + + def set_done(self, i, v): + self.cells[i] = [v] + + def already_done(self, i): + return len(self.cells[i]) == 1 + + def remove(self, i, v): + if v in self.cells[i]: + self.cells[i].remove(v) + return True + else: + return False + + def remove_all(self, v): + for i in range(self.count): + self.remove(i, v) + + def remove_unfixed(self, v): + changed = False + for i in range(self.count): + if not self.already_done(i): + if self.remove(i, v): + changed = True + return changed + + def filter_tiles(self, tiles): + for v in range(8): + if tiles[v] == 0: + self.remove_all(v) + + def next_cell_min_choice(self): + minlen = 10 + mini = -1 + for i in range(self.count): + if 1 < len(self.cells[i]) < minlen: + minlen = len(self.cells[i]) + mini = i + return mini + + def next_cell_max_choice(self): + maxlen = 1 + maxi = -1 + for i in range(self.count): + if maxlen < len(self.cells[i]): + maxlen = len(self.cells[i]) + maxi = i + return maxi + + def next_cell_highest_value(self): + maxval = -1 + maxi = -1 + for i in range(self.count): + if (not self.already_done(i)): + maxvali = max(k for k in self.cells[i] if k != EMPTY) + if maxval < maxvali: + maxval = maxvali + maxi = i + return maxi + + def next_cell_first(self): + for i in range(self.count): + if (not self.already_done(i)): + return i + return -1 + + def next_cell_max_neighbors(self, pos): + maxn = -1 + maxi = -1 + for i in range(self.count): + if not self.already_done(i): + cells_around = pos.hex.get_by_id(i).links + n = sum(1 if (self.already_done(nid) and (self[nid][0] != EMPTY)) else 0 + for nid in cells_around) + if n > maxn: + maxn = n + maxi = i + return maxi + + def next_cell_min_neighbors(self, pos): + minn = 7 + mini = -1 + for i in range(self.count): + if not self.already_done(i): + cells_around = pos.hex.get_by_id(i).links + n = sum(1 if (self.already_done(nid) and (self[nid][0] != EMPTY)) else 0 + for nid in cells_around) + if n < minn: + minn = n + mini = i + return mini + + def next_cell(self, pos, strategy=HIGHEST_VALUE_STRATEGY): + if strategy == Done.HIGHEST_VALUE_STRATEGY: + return self.next_cell_highest_value() + elif strategy == Done.MIN_CHOICE_STRATEGY: + return self.next_cell_min_choice() + elif strategy == Done.MAX_CHOICE_STRATEGY: + return self.next_cell_max_choice() + elif strategy == Done.FIRST_STRATEGY: + return self.next_cell_first() + elif strategy == Done.MAX_NEIGHBORS_STRATEGY: + return self.next_cell_max_neighbors(pos) + elif strategy == Done.MIN_NEIGHBORS_STRATEGY: + return self.next_cell_min_neighbors(pos) + else: + raise Exception("Wrong strategy: %d" % strategy) + +################################## + + +class Node(object): + + def __init__(self, pos, id, links): + self.pos = pos + self.id = id + self.links = links + +################################## + + +class Hex(object): + + def __init__(self, size): + self.size = size + self.count = 3 * size * (size - 1) + 1 + self.nodes_by_id = self.count * [None] + self.nodes_by_pos = {} + id = 0 + for y in range(size): + for x in range(size + y): + pos = (x, y) + node = Node(pos, id, []) + self.nodes_by_pos[pos] = node + self.nodes_by_id[node.id] = node + id += 1 + for y in range(1, size): + for x in range(y, size * 2 - 1): + ry = size + y - 1 + pos = (x, ry) + node = Node(pos, id, []) + self.nodes_by_pos[pos] = node + self.nodes_by_id[node.id] = node + id += 1 + + def link_nodes(self): + for node in self.nodes_by_id: + (x, y) = node.pos + for dir in DIRS: + nx = x + dir.x + ny = y + dir.y + if self.contains_pos((nx, ny)): + node.links.append(self.nodes_by_pos[(nx, ny)].id) + + def contains_pos(self, pos): + return pos in self.nodes_by_pos + + def get_by_pos(self, pos): + return self.nodes_by_pos[pos] + + def get_by_id(self, id): + return self.nodes_by_id[id] + + +################################## +class Pos(object): + + def __init__(self, hex, tiles, done=None): + self.hex = hex + self.tiles = tiles + self.done = Done(hex.count) if done is None else done + + def clone(self): + return Pos(self.hex, self.tiles, self.done.clone()) + +################################## + + +def constraint_pass(pos, last_move=None): + changed = False + left = pos.tiles[:] + done = pos.done + + # Remove impossible values from free cells + free_cells = (range(done.count) if last_move is None + else pos.hex.get_by_id(last_move).links) + for i in free_cells: + if not done.already_done(i): + vmax = 0 + vmin = 0 + cells_around = pos.hex.get_by_id(i).links + for nid in cells_around: + if done.already_done(nid): + if done[nid][0] != EMPTY: + vmin += 1 + vmax += 1 + else: + vmax += 1 + + for num in range(7): + if (num < vmin) or (num > vmax): + if done.remove(i, num): + changed = True + + # Computes how many of each value is still free + for cell in done.cells: + if len(cell) == 1: + left[cell[0]] -= 1 + + for v in range(8): + # If there is none, remove the possibility from all tiles + if (pos.tiles[v] > 0) and (left[v] == 0): + if done.remove_unfixed(v): + changed = True + else: + possible = sum((1 if v in cell else 0) for cell in done.cells) + # If the number of possible cells for a value is exactly the number of available tiles + # put a tile in each cell + if pos.tiles[v] == possible: + for i in range(done.count): + cell = done.cells[i] + if (not done.already_done(i)) and (v in cell): + done.set_done(i, v) + changed = True + + # Force empty or non-empty around filled cells + filled_cells = (range(done.count) if last_move is None + else [last_move]) + for i in filled_cells: + if done.already_done(i): + num = done[i][0] + empties = 0 + filled = 0 + unknown = [] + cells_around = pos.hex.get_by_id(i).links + for nid in cells_around: + if done.already_done(nid): + if done[nid][0] == EMPTY: + empties += 1 + else: + filled += 1 + else: + unknown.append(nid) + if len(unknown) > 0: + if num == filled: + for u in unknown: + if EMPTY in done[u]: + done.set_done(u, EMPTY) + changed = True + # else: + # raise Exception("Houston, we've got a problem") + elif num == filled + len(unknown): + for u in unknown: + if done.remove(u, EMPTY): + changed = True + + return changed + + +ASCENDING = 1 +DESCENDING = -1 + + +def find_moves(pos, strategy, order): + done = pos.done + cell_id = done.next_cell(pos, strategy) + if cell_id < 0: + return [] + + if order == ASCENDING: + return [(cell_id, v) for v in done[cell_id]] + else: + # Try higher values first and EMPTY last + moves = list(reversed([(cell_id, v) + for v in done[cell_id] if v != EMPTY])) + if EMPTY in done[cell_id]: + moves.append((cell_id, EMPTY)) + return moves + + +def play_move(pos, move): + (cell_id, i) = move + pos.done.set_done(cell_id, i) + + +def print_pos(pos, output): + hex = pos.hex + done = pos.done + size = hex.size + for y in range(size): + print(" " * (size - y - 1), end="", file=output) + for x in range(size + y): + pos2 = (x, y) + id = hex.get_by_pos(pos2).id + if done.already_done(id): + c = str(done[id][0]) if done[id][0] != EMPTY else "." + else: + c = "?" + print("%s " % c, end="", file=output) + print(end="\n", file=output) + for y in range(1, size): + print(" " * y, end="", file=output) + for x in range(y, size * 2 - 1): + ry = size + y - 1 + pos2 = (x, ry) + id = hex.get_by_pos(pos2).id + if done.already_done(id): + c = str(done[id][0]) if done[id][0] != EMPTY else "." + else: + c = "?" + print("%s " % c, end="", file=output) + print(end="\n", file=output) + + +OPEN = 0 +SOLVED = 1 +IMPOSSIBLE = -1 + + +def solved(pos, output, verbose=False): + hex = pos.hex + tiles = pos.tiles[:] + done = pos.done + exact = True + all_done = True + for i in range(hex.count): + if len(done[i]) == 0: + return IMPOSSIBLE + elif done.already_done(i): + num = done[i][0] + tiles[num] -= 1 + if (tiles[num] < 0): + return IMPOSSIBLE + vmax = 0 + vmin = 0 + if num != EMPTY: + cells_around = hex.get_by_id(i).links + for nid in cells_around: + if done.already_done(nid): + if done[nid][0] != EMPTY: + vmin += 1 + vmax += 1 + else: + vmax += 1 + + if (num < vmin) or (num > vmax): + return IMPOSSIBLE + if num != vmin: + exact = False + else: + all_done = False + + if (not all_done) or (not exact): + return OPEN + + print_pos(pos, output) + return SOLVED + + +def solve_step(prev, strategy, order, output, first=False): + if first: + pos = prev.clone() + while constraint_pass(pos): + pass + else: + pos = prev + + moves = find_moves(pos, strategy, order) + if len(moves) == 0: + return solved(pos, output) + else: + for move in moves: + # print("Trying (%d, %d)" % (move[0], move[1])) + ret = OPEN + new_pos = pos.clone() + play_move(new_pos, move) + # print_pos(new_pos) + while constraint_pass(new_pos, move[0]): + pass + cur_status = solved(new_pos, output) + if cur_status != OPEN: + ret = cur_status + else: + ret = solve_step(new_pos, strategy, order, output) + if ret == SOLVED: + return SOLVED + return IMPOSSIBLE + + +def check_valid(pos): + hex = pos.hex + tiles = pos.tiles + # fill missing entries in tiles + tot = 0 + for i in range(8): + if tiles[i] > 0: + tot += tiles[i] + else: + tiles[i] = 0 + # check total + if tot != hex.count: + raise Exception( + "Invalid input. Expected %d tiles, got %d." % (hex.count, tot)) + + +def solve(pos, strategy, order, output): + check_valid(pos) + return solve_step(pos, strategy, order, output, first=True) + + +# TODO Write an 'iterator' to go over all x,y positions + +def read_file(file): + lines = [line.strip("\r\n") for line in file.splitlines()] + size = int(lines[0]) + hex = Hex(size) + linei = 1 + tiles = 8 * [0] + done = Done(hex.count) + for y in range(size): + line = lines[linei][size - y - 1:] + p = 0 + for x in range(size + y): + tile = line[p:p + 2] + p += 2 + if tile[1] == ".": + inctile = EMPTY + else: + inctile = int(tile) + tiles[inctile] += 1 + # Look for locked tiles + if tile[0] == "+": + # print("Adding locked tile: %d at pos %d, %d, id=%d" % + # (inctile, x, y, hex.get_by_pos((x, y)).id)) + done.set_done(hex.get_by_pos((x, y)).id, inctile) + + linei += 1 + for y in range(1, size): + ry = size - 1 + y + line = lines[linei][y:] + p = 0 + for x in range(y, size * 2 - 1): + tile = line[p:p + 2] + p += 2 + if tile[1] == ".": + inctile = EMPTY + else: + inctile = int(tile) + tiles[inctile] += 1 + # Look for locked tiles + if tile[0] == "+": + # print("Adding locked tile: %d at pos %d, %d, id=%d" % + # (inctile, x, ry, hex.get_by_pos((x, ry)).id)) + done.set_done(hex.get_by_pos((x, ry)).id, inctile) + linei += 1 + hex.link_nodes() + done.filter_tiles(tiles) + return Pos(hex, tiles, done) + + +def solve_file(file, strategy, order, output): + pos = read_file(file) + solve(pos, strategy, order, output) + + +LEVELS = {} + +LEVELS[2] = (""" +2 + . 1 + . 1 1 + 1 . +""", """\ + 1 1 +. . . + 1 1 +""") + +LEVELS[10] = (""" +3 + +.+. . + +. 0 . 2 + . 1+2 1 . + 2 . 0+. + .+.+. +""", """\ + . . 1 + . 1 . 2 +0 . 2 2 . + . . . . + 0 . . +""") + +LEVELS[20] = (""" +3 + . 5 4 + . 2+.+1 + . 3+2 3 . + +2+. 5 . + . 3 . +""", """\ + 3 3 2 + 4 5 . 1 +3 5 2 . . + 2 . . . + . . . +""") + +LEVELS[25] = (""" +3 + 4 . . + . . 2 . + 4 3 2 . 4 + 2 2 3 . + 4 2 4 +""", """\ + 3 4 2 + 2 4 4 . +. . . 4 2 + . 2 4 3 + . 2 . +""") + +LEVELS[30] = (""" +4 + 5 5 . . + 3 . 2+2 6 + 3 . 2 . 5 . + . 3 3+4 4 . 3 + 4 5 4 . 5 4 + 5+2 . . 3 + 4 . . . +""", """\ + 3 4 3 . + 4 6 5 2 . + 2 5 5 . . 2 +. . 5 4 . 4 3 + . 3 5 4 5 4 + . 2 . 3 3 + . . . . +""") + +LEVELS[36] = (""" +4 + 2 1 1 2 + 3 3 3 . . + 2 3 3 . 4 . + . 2 . 2 4 3 2 + 2 2 . . . 2 + 4 3 4 . . + 3 2 3 3 +""", """\ + 3 4 3 2 + 3 4 4 . 3 + 2 . . 3 4 3 +2 . 1 . 3 . 2 + 3 3 . 2 . 2 + 3 . 2 . 2 + 2 2 . 1 +""") + + +def run(level): + board, solution = LEVELS[level] + order = DESCENDING + strategy = Done.FIRST_STRATEGY + stream = io.StringIO() + + board = board.strip() + expected = solution.rstrip() + + + stream = io.StringIO() + solve_file(board, strategy, order, stream) + output = stream.getvalue() + stream = None + + output = '\n'.join(line.rstrip() for line in output.splitlines()) + if output != expected: + raise AssertionError("got a wrong answer:\n%s\nexpected: %s" + % (output, expected)) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--level", type=int, + choices=sorted(LEVELS), + default=DEFAULT_LEVEL, + help="Hexiom board level (default: %s)" + % DEFAULT_LEVEL) + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + levels = sorted(LEVELS) + run(args.level) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py b/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py new file mode 100644 index 00000000..f73852eb --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py @@ -0,0 +1,56 @@ +import sys +import subprocess + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey +from pyperformance.venv import get_venv_program + + +def get_hg_version(hg_bin): + # Fast-path: use directly the Python module + try: + from mercurial.__version__ import version + if isinstance(version, bytes): + return version.decode('utf8') + else: + return version + except ImportError: + pass + + # Slow-path: run the "hg --version" command + proc = subprocess.Popen([sys.executable, hg_bin, "--version"], + stdout=subprocess.PIPE, + universal_newlines=True) + stdout = proc.communicate()[0] + if proc.returncode: + print("ERROR: Mercurial command failed!") + sys.exit(proc.returncode) + return stdout.splitlines()[0] + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + hg_bin = get_venv_program('hg') + get_hg_version(hg_bin) + + command = [sys.executable, hg_bin, "help"] + subprocces.run(command) + + profiler.disable() + s = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py b/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py new file mode 100644 index 00000000..8b025da9 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py @@ -0,0 +1,51 @@ +"""Wrapper script for testing the performance of the html5lib HTML 5 parser. + +The input data is the spec document for HTML 5, written in HTML 5. +The spec was pulled from http://svn.whatwg.org/webapps/index. +""" +import io +import os.path + +import html5lib + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +__author__ = "collinwinter@google.com (Collin Winter)" + + +def bench_html5lib(html_file): + html_file.seek(0) + html5lib.parse(html_file) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + # Get all our IO over with early. + filename = os.path.join(os.path.dirname(__file__), + "data", "w3_tr_html5.html") + with open(filename, "rb") as fp: + html_file = io.BytesIO(fp.read()) + + bench_html5lib(html_file) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py b/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py new file mode 100644 index 00000000..0f07d59d --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py @@ -0,0 +1,74 @@ +import json +import sys + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +EMPTY = ({}, 2000) +SIMPLE_DATA = {'key1': 0, 'key2': True, 'key3': 'value', 'key4': 'foo', + 'key5': 'string'} +SIMPLE = (SIMPLE_DATA, 1000) +NESTED_DATA = {'key1': 0, 'key2': SIMPLE[0], 'key3': 'value', 'key4': SIMPLE[0], + 'key5': SIMPLE[0], 'key': '\u0105\u0107\u017c'} +NESTED = (NESTED_DATA, 1000) +HUGE = ([NESTED[0]] * 1000, 1) + +CASES = ['EMPTY', 'SIMPLE', 'NESTED', 'HUGE'] + + +def bench_json_dumps(data): + for obj, count_it in data: + for _ in count_it: + json.dumps(obj) + + +def add_cmdline_args(cmd, args): + if args.cases: + cmd.extend(("--cases", args.cases)) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--cases", + help="Comma separated list of cases. Available cases: %s. By default, run all cases." + % ', '.join(CASES)) + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if args.cases: + cases = [] + for case in args.cases.split(','): + case = case.strip() + if case: + cases.append(case) + if not cases: + print("ERROR: empty list of cases") + sys.exit(1) + else: + cases = CASES + + data = [] + for case in cases: + obj, count = globals()[case] + data.append((obj, range(count))) + + bench_json_dumps(data) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py b/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py new file mode 100644 index 00000000..c5a2226f --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py @@ -0,0 +1,124 @@ + +"""Script for testing the performance of json parsing and serialization. + +This will dump/load several real world-representative objects a few +thousand times. The methodology below was chosen for was chosen to be similar +to real-world scenarios which operate on single objects at a time. +""" + +# Python imports +import json +import random +import sys + +# Local imports +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DICT = { + 'ads_flags': 0, + 'age': 18, + 'bulletin_count': 0, + 'comment_count': 0, + 'country': 'BR', + 'encrypted_id': 'G9urXXAJwjE', + 'favorite_count': 9, + 'first_name': '', + 'flags': 412317970704, + 'friend_count': 0, + 'gender': 'm', + 'gender_for_display': 'Male', + 'id': 302935349, + 'is_custom_profile_icon': 0, + 'last_name': '', + 'locale_preference': 'pt_BR', + 'member': 0, + 'tags': ['a', 'b', 'c', 'd', 'e', 'f', 'g'], + 'profile_foo_id': 827119638, + 'secure_encrypted_id': 'Z_xxx2dYx3t4YAdnmfgyKw', + 'session_number': 2, + 'signup_id': '201-19225-223', + 'status': 'A', + 'theme': 1, + 'time_created': 1225237014, + 'time_updated': 1233134493, + 'unread_message_count': 0, + 'user_group': '0', + 'username': 'collinwinter', + 'play_count': 9, + 'view_count': 7, + 'zip': ''} + +TUPLE = ( + [265867233, 265868503, 265252341, 265243910, 265879514, + 266219766, 266021701, 265843726, 265592821, 265246784, + 265853180, 45526486, 265463699, 265848143, 265863062, + 265392591, 265877490, 265823665, 265828884, 265753032], 60) + + +def mutate_dict(orig_dict, random_source): + new_dict = dict(orig_dict) + for key, value in new_dict.items(): + rand_val = random_source.random() * sys.maxsize + if isinstance(key, (int, bytes, str)): + new_dict[key] = type(key)(rand_val) + return new_dict + + +random_source = random.Random(5) # Fixed seed. +DICT_GROUP = [mutate_dict(DICT, random_source) for _ in range(3)] + + +def bench_json_loads(objs): + for obj in objs: + # 20 loads + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + json.loads(obj) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + json_dict = json.dumps(DICT) + json_tuple = json.dumps(TUPLE) + json_dict_group = json.dumps(DICT_GROUP) + objs = (json_dict, json_tuple, json_dict_group) + + bench_json_loads(objs) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py b/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py new file mode 100644 index 00000000..8fd86d19 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py @@ -0,0 +1,166 @@ +""" +Script for testing the performance of logging simple messages. + +Rationale for logging_silent by Antoine Pitrou: + +"The performance of silent logging calls is actually important for all +applications which have debug() calls in their critical paths. This is +quite common in network and/or distributed programming where you want to +allow logging many events for diagnosis of unexpected runtime issues +(because many unexpected conditions can appear), but with those logs +disabled by default for performance and readability reasons." + +https://mail.python.org/pipermail/speed/2017-May/000576.html +""" + +# Python imports +import io +import logging + +# Third party imports +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# A simple format for parametered logging +FORMAT = 'important: %s' +MESSAGE = 'some important information to be logged' + + +def truncate_stream(stream): + stream.seek(0) + stream.truncate() + + +def bench_silent(loops, logger, stream): + truncate_stream(stream) + + # micro-optimization: use fast local variables + m = MESSAGE + range_it = range(loops) + t0 = pyperf.perf_counter() + + for _ in range_it: + # repeat 10 times + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + logger.debug(m) + + dt = pyperf.perf_counter() - t0 + + if len(stream.getvalue()) != 0: + raise ValueError("stream is expected to be empty") + + return dt + + +def bench_simple_output(loops, logger, stream): + truncate_stream(stream) + + # micro-optimization: use fast local variables + m = MESSAGE + range_it = range(loops) + t0 = pyperf.perf_counter() + + for _ in range_it: + # repeat 10 times + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + logger.warning(m) + + dt = pyperf.perf_counter() - t0 + + lines = stream.getvalue().splitlines() + if len(lines) != loops * 10: + raise ValueError("wrong number of lines") + + return dt + + +def bench_formatted_output(logger, stream): + truncate_stream(stream) + + # micro-optimization: use fast local variables + fmt = FORMAT + msg = MESSAGE + + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + logger.warning(fmt, msg) + + lines = stream.getvalue().splitlines() + + +BENCHMARKS = { + "silent": bench_silent, + "simple": bench_simple_output, + "format": bench_formatted_output, +} + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("benchmark", + nargs='?', + choices=sorted(BENCHMARKS)) + + options = parser.parse_args() + + profiler = Profile(builtins=options.builtins) + profiler.enable() + + # NOTE: StringIO performance will impact the results... + stream = io.StringIO() + + handler = logging.StreamHandler(stream=stream) + logger = logging.getLogger("benchlogger") + logger.propagate = False + logger.addHandler(handler) + logger.setLevel(logging.WARNING) + + if options.benchmark: + benchmarks = (options.benchmark) + else: + benchmarks = sorted(BENCHMARKS) + + for bench in benchmarks: + name = 'logging_%s' % bench + bench_func = BENCHMARKS[bench] + bench_formatted_output(logger, stream) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(options.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py b/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py new file mode 100644 index 00000000..b5ac2fc1 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py @@ -0,0 +1,159 @@ +""" +Benchmark for test the performance of Mako templates engine. +Includes: + -two template inherences + -HTML escaping, XML escaping, URL escaping, whitespace trimming + -function defitions and calls + -forloops +""" + +import functools +import sys + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +# Mako imports (w/o markupsafe) +sys.modules['markupsafe'] = None + +import mako # noqa +from mako.template import Template # noqa +from mako.lookup import TemplateLookup # noqa + + +__author__ = "virhilo@gmail.com (Lukasz Fidosz)" + +LOREM_IPSUM = """Quisque lobortis hendrerit posuere. Curabitur +aliquet consequat sapien molestie pretium. Nunc adipiscing luc +tus mi, viverra porttitor lorem vulputate et. Ut at purus sem, +sed tincidunt ante. Vestibulum ante ipsum primis in faucibus +orci luctus et ultrices posuere cubilia Curae; Praesent pulvinar +sodales justo at congue. Praesent aliquet facilisis nisl a +molestie. Sed tempus nisl ut augue eleifend tincidunt. Sed a +lacinia nulla. Cras tortor est, mollis et consequat at, +vulputate et orci. Nulla sollicitudin""" + +BASE_TEMPLATE = """ +<%def name="render_table(table)"> + + % for row in table: + + % for col in row: + + % endfor + + % endfor +
${col|h}
+ +<%def name="img(src, alt)"> + ${alt} + + + ${title|h,trim} + + ${next.body()} + + +""" + +PAGE_TEMPLATE = """ +<%inherit file="base.mako"/> + + % for row in table: + + % for col in row: + + % endfor + + % endfor +
${col}
+% for nr in range(img_count): + ${parent.img('/foo/bar/baz.png', 'no image :o')} +% endfor +${next.body()} +% for nr in paragraphs: +

${lorem|x}

+% endfor +${parent.render_table(table)} +""" + +CONTENT_TEMPLATE = """ +<%inherit file="page.mako"/> +<%def name="fun1()"> + fun1 + +<%def name="fun2()"> + fun2 + +<%def name="fun3()"> + foo3 + +<%def name="fun4()"> + foo4 + +<%def name="fun5()"> + foo5 + +<%def name="fun6()"> + foo6 + +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Nam laoreet justo in velit faucibus lobortis. Sed dictum sagittis +volutpat. Sed adipiscing vestibulum consequat. Nullam laoreet, ante +nec pretium varius, libero arcu porttitor orci, id cursus odio nibh +nec leo. Vestibulum dapibus pellentesque purus, sed bibendum tortor +laoreet id. Praesent quis sodales ipsum. Fusce ut ligula sed diam +pretium sagittis vel at ipsum. Nulla sagittis sem quam, et volutpat +velit. Fusce dapibus ligula quis lectus ultricies tempor. Pellente

+${fun1()} +${fun2()} +${fun3()} +${fun4()} +${fun5()} +${fun6()} +""" + + +def bench_mako(table_size, nparagraph, img_count): + lookup = TemplateLookup() + lookup.put_string('base.mako', BASE_TEMPLATE) + lookup.put_string('page.mako', PAGE_TEMPLATE) + + template = Template(CONTENT_TEMPLATE, lookup=lookup) + + table = [range(table_size) for i in range(table_size)] + paragraphs = range(nparagraph) + title = 'Hello world!' + + func = functools.partial(template.render, + table=table, paragraphs=paragraphs, + lorem=LOREM_IPSUM, title=title, + img_count=img_count, range=range) + func() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + table_size = 150 + nparagraph = 50 + img_count = 50 + bench_mako(table_size, nparagraph, img_count) + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py b/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py new file mode 100644 index 00000000..083a1146 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py @@ -0,0 +1,281 @@ +import collections +from collections import defaultdict +from fractions import Fraction + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +def topoSort(roots, getParents): + """Return a topological sorting of nodes in a graph. + + roots - list of root nodes to search from + getParents - function which returns the parents of a given node + """ + + results = [] + visited = set() + + # Use iterative version to avoid stack limits for large datasets + stack = [(node, 0) for node in roots] + while stack: + current, state = stack.pop() + if state == 0: + # before recursing + if current not in visited: + visited.add(current) + stack.append((current, 1)) + stack.extend((parent, 0) for parent in getParents(current)) + else: + # after recursing + assert(current in visited) + results.append(current) + return results + + +def getDamages(L, A, D, B, stab, te): + x = (2 * L) // 5 + x = ((x + 2) * A * B) // (D * 50) + 2 + if stab: + x += x // 2 + x = int(x * te) + return [(x * z) // 255 for z in range(217, 256)] + + +def getCritDist(L, p, A1, A2, D1, D2, B, stab, te): + p = min(p, Fraction(1)) + norm = getDamages(L, A1, D1, B, stab, te) + crit = getDamages(L * 2, A2, D2, B, stab, te) + + dist = defaultdict(Fraction) + for mult, vals in zip([1 - p, p], [norm, crit]): + mult /= len(vals) + for x in vals: + dist[x] += mult + return dist + + +def plus12(x): + return x + x // 8 + + +stats_t = collections.namedtuple('stats_t', ['atk', 'df', 'speed', 'spec']) +NOMODS = stats_t(0, 0, 0, 0) + + +fixeddata_t = collections.namedtuple( + 'fixeddata_t', ['maxhp', 'stats', 'lvl', 'badges', 'basespeed']) +halfstate_t = collections.namedtuple( + 'halfstate_t', ['fixed', 'hp', 'status', 'statmods', 'stats']) + + +def applyHPChange(hstate, change): + hp = min(hstate.fixed.maxhp, max(0, hstate.hp + change)) + return hstate._replace(hp=hp) + + +def applyBadgeBoosts(badges, stats): + return stats_t(*[(plus12(x) if b else x) for x, b in zip(stats, badges)]) + + +attack_stats_t = collections.namedtuple( + 'attack_stats_t', ['power', 'isspec', 'stab', 'te', 'crit']) +attack_data = { + 'Ember': attack_stats_t(40, True, True, 0.5, False), + 'Dig': attack_stats_t(100, False, False, 1, False), + 'Slash': attack_stats_t(70, False, False, 1, True), + 'Water Gun': attack_stats_t(40, True, True, 2, False), + 'Bubblebeam': attack_stats_t(65, True, True, 2, False), +} + + +def _applyActionSide1(state, act): + me, them, extra = state + + if act == 'Super Potion': + me = applyHPChange(me, 50) + return {(me, them, extra): Fraction(1)} + + mdata = attack_data[act] + aind = 3 if mdata.isspec else 0 + dind = 3 if mdata.isspec else 1 + pdiv = 64 if mdata.crit else 512 + dmg_dist = getCritDist(me.fixed.lvl, Fraction(me.fixed.basespeed, pdiv), + me.stats[aind], me.fixed.stats[aind], them.stats[ + dind], them.fixed.stats[dind], + mdata.power, mdata.stab, mdata.te) + + dist = defaultdict(Fraction) + for dmg, p in dmg_dist.items(): + them2 = applyHPChange(them, -dmg) + dist[me, them2, extra] += p + return dist + + +def _applyAction(state, side, act): + if side == 0: + return _applyActionSide1(state, act) + else: + me, them, extra = state + dist = _applyActionSide1((them, me, extra), act) + return {(k[1], k[0], k[2]): v for k, v in dist.items()} + + +class Battle(object): + + def __init__(self): + self.successors = {} + self.min = defaultdict(float) + self.max = defaultdict(lambda: 1.0) + self.frozen = set() + + self.win = 4, True + self.loss = 4, False + self.max[self.loss] = 0.0 + self.min[self.win] = 1.0 + self.frozen.update([self.win, self.loss]) + + def _getSuccessorsA(self, statep): + st, state = statep + for action in ['Dig', 'Super Potion']: + yield (1, state, action) + + def _applyActionPair(self, state, side1, act1, side2, act2, dist, pmult): + for newstate, p in _applyAction(state, side1, act1).items(): + if newstate[0].hp == 0: + newstatep = self.loss + elif newstate[1].hp == 0: + newstatep = self.win + else: + newstatep = 2, newstate, side2, act2 + dist[newstatep] += p * pmult + + def _getSuccessorsB(self, statep): + st, state, action = statep + dist = defaultdict(Fraction) + for eact, p in [('Water Gun', Fraction(64, 130)), + ('Bubblebeam', Fraction(66, 130))]: + priority1 = state[0].stats.speed + \ + 10000 * (action == 'Super Potion') + priority2 = state[1].stats.speed + 10000 * (action == 'X Defend') + + if priority1 > priority2: + self._applyActionPair(state, 0, action, 1, eact, dist, p) + elif priority1 < priority2: + self._applyActionPair(state, 1, eact, 0, action, dist, p) + else: + self._applyActionPair(state, 0, action, 1, eact, dist, p / 2) + self._applyActionPair(state, 1, eact, 0, action, dist, p / 2) + + return {k: float(p) for k, p in dist.items() if p > 0} + + def _getSuccessorsC(self, statep): + st, state, side, action = statep + dist = defaultdict(Fraction) + for newstate, p in _applyAction(state, side, action).items(): + if newstate[0].hp == 0: + newstatep = self.loss + elif newstate[1].hp == 0: + newstatep = self.win + else: + newstatep = 0, newstate + dist[newstatep] += p + return {k: float(p) for k, p in dist.items() if p > 0} + + def getSuccessors(self, statep): + try: + return self.successors[statep] + except KeyError: + st = statep[0] + if st == 0: + result = list(self._getSuccessorsA(statep)) + else: + if st == 1: + dist = self._getSuccessorsB(statep) + elif st == 2: + dist = self._getSuccessorsC(statep) + result = sorted(dist.items(), key=lambda t: (-t[1], t[0])) + self.successors[statep] = result + return result + + def getSuccessorsList(self, statep): + if statep[0] == 4: + return [] + temp = self.getSuccessors(statep) + if statep[0] != 0: + temp = list(zip(*temp))[0] if temp else [] + return temp + + def evaluate(self, tolerance=0.15): + badges = 1, 0, 0, 0 + + starfixed = fixeddata_t(59, stats_t(40, 44, 56, 50), 11, NOMODS, 115) + starhalf = halfstate_t(starfixed, 59, 0, NOMODS, + stats_t(40, 44, 56, 50)) + charfixed = fixeddata_t(63, stats_t(39, 34, 46, 38), 26, badges, 65) + charhalf = halfstate_t(charfixed, 63, 0, NOMODS, applyBadgeBoosts( + badges, stats_t(39, 34, 46, 38))) + initial_state = charhalf, starhalf, 0 + initial_statep = 0, initial_state + + dmin, dmax, frozen = self.min, self.max, self.frozen + stateps = topoSort([initial_statep], self.getSuccessorsList) + + itercount = 0 + while dmax[initial_statep] - dmin[initial_statep] > tolerance: + itercount += 1 + + for sp in stateps: + if sp in frozen: + continue + + if sp[0] == 0: + # choice node + dmin[sp] = max(dmin[sp2] for sp2 in self.getSuccessors(sp)) + dmax[sp] = max(dmax[sp2] for sp2 in self.getSuccessors(sp)) + else: + dmin[sp] = sum(dmin[sp2] * p for sp2, + p in self.getSuccessors(sp)) + dmax[sp] = sum(dmax[sp2] * p for sp2, + p in self.getSuccessors(sp)) + + if dmin[sp] >= dmax[sp]: + dmax[sp] = dmin[sp] = (dmin[sp] + dmax[sp]) / 2 + frozen.add(sp) + return (dmax[initial_statep] + dmin[initial_statep]) / 2 + + +def bench_mdp(): + expected = 0.89873589887 + max_diff = 1e-6 + result = Battle().evaluate(0.192) + + if abs(result - expected) > max_diff: + raise Exception("invalid result: got %s, expected %s " + "(diff: %s, max diff: %s)" + % (result, expected, result - expected, max_diff)) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_mdp() + + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py b/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py new file mode 100644 index 00000000..865d3ccd --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py @@ -0,0 +1,230 @@ +""" +Meteor Puzzle board: +http://benchmarksgame.alioth.debian.org/u32/meteor-description.html#meteor + +The Computer Language Benchmarks Game +http://benchmarksgame.alioth.debian.org/ + +contributed by Daniel Nanz, 2008-08-21 +""" + +from bisect import bisect +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +SOLVE_ARG = 60 + +WIDTH, HEIGHT = 5, 10 +DIR_NO = 6 +S, E = WIDTH * HEIGHT, 2 +SE = S + (E / 2) +SW = SE - E +W, NW, NE = -E, -SE, -SW + +SOLUTIONS = [ + '00001222012661126155865558633348893448934747977799', + '00001222012771127148774485464855968596835966399333', + '00001222012771127148774485494855998596835966366333', + '00001222012771127148774485994855948596835966366333', + '00001222012771127166773863384653846538445584959999', + '00001222012771127183778834833348555446554666969999', + '00001222012771127183778834833348555446554966699996', + '00001223012331123166423564455647456775887888979999', + '00001555015541144177484726877268222683336689399993', + '00001555015541144177484728677286222863338669399993', + '00001599015591159148594482224827748276837766366333', + '00001777017871184155845558449984669662932629322333', + '00004222042664426774996879687759811598315583153331', + '00004222042774427384773183331866118615586555969999', + '00004223042334423784523785771855718566186611969999', + '00004227042874428774528735833155831566316691169999', + '00004333045534455384175781777812228116286662969999', + '00004333045934459384559185991866118612286727267772', + '00004333047734427384277182221866118615586555969999', + '00004555045514411224172621768277368736683339899998', + '00004555045514411224172721777299998966836688368333', + '00004555045534413334132221177266172677886888969999', + '00004555045534473334739967792617926192661882211888', + '00004555045564466694699992288828811233317273177731', + '00004555045564466694699997773172731233312881122888', + '00004555045564496664999962288828811233317273177731', + '00004555045564496664999967773172731233312881122888', + '00004555045584411884171187722866792679236992369333', + '00004555045584411884191189999832226333267372677766', + '00004555045584411884191189999866222623336727367773', + '13335138551389511895778697869947762446624022240000', + '13777137271333211882888226999946669446554055540000', + '13777137271333211882888229999649666446554055540000', + '27776272768221681166819958195548395443954033340000', + '33322392623926696648994485554855148117871077710000', + '33366366773867284772842228449584195119551099510000', + '33366366953869584955849958447784172117721022210000', + '33366366953869589955849458447784172117721022210000', + '33386388663866989999277712727142211441554055540000', + '33396329963297629766822778117148811448554055540000', + '33399366953869586955846458447784172117721022210000', + '37776372763332622266899998119148811448554055540000', + '39999396683336822268277682748477144114551055510000', + '39999398663338622286277862748477144114551055510000', + '66777627376233362223899998119148811448554055540000', + '69999666945564455584333843887738172117721022210000', + '88811228816629162971629776993743337443554055540000', + '88822118821333213727137776999946669446554055540000', + '88822118821333213727137779999649666446554055540000', + '89999893338663786377286712627142211441554055540000', + '99777974743984439884333685556855162116621022210000', + '99995948554483564835648336837766172117721022210000', + '99996119661366513855133853782547782447824072240000', + '99996911668166581755817758732548732443324032240000', + '99996926668261182221877718757148355443554033340000', + '99996955568551681166812228177248372443774033340000', + '99996955568551681166813338137748372447724022240000', + '99996966645564455584333843887738172117721022210000', + '99996988868877627166277112223143331443554055540000', + '99997988878857765474655446532466132113321032210000'] + + +def rotate(ido, rd={E: NE, NE: NW, NW: W, W: SW, SW: SE, SE: E}): + return [rd[o] for o in ido] + + +def flip(ido, fd={E: E, NE: SE, NW: SW, W: W, SW: NW, SE: NE}): + return [fd[o] for o in ido] + + +def permute(ido, r_ido, rotate=rotate, flip=flip): + ps = [ido] + for r in range(DIR_NO - 1): + ps.append(rotate(ps[-1])) + if ido == r_ido: # C2-symmetry + ps = ps[0:DIR_NO // 2] + for pp in ps[:]: + ps.append(flip(pp)) + return ps + + +def convert(ido): + '''incremental direction offsets -> "coordinate offsets" ''' + out = [0] + for o in ido: + out.append(out[-1] + o) + return list(set(out)) + + +def get_footprints(board, cti, pieces): + fps = [[[] for p in range(len(pieces))] for ci in range(len(board))] + for c in board: + for pi, p in enumerate(pieces): + for pp in p: + fp = frozenset([cti[c + o] for o in pp if (c + o) in cti]) + if len(fp) == 5: + fps[min(fp)][pi].append(fp) + return fps + + +def get_senh(board, cti): + '''-> south-east neighborhood''' + se_nh = [] + nh = [E, SW, SE] + for c in board: + se_nh.append(frozenset([cti[c + o] for o in nh if (c + o) in cti])) + return se_nh + + +def get_puzzle(width, height): + board = [E * x + S * y + (y % 2) + for y in range(height) + for x in range(width)] + cti = dict((board[i], i) for i in range(len(board))) + + # Incremental direction offsets + idos = [[E, E, E, SE], + [SE, SW, W, SW], + [W, W, SW, SE], + [E, E, SW, SE], + [NW, W, NW, SE, SW], + [E, E, NE, W], + [NW, NE, NE, W], + [NE, SE, E, NE], + [SE, SE, E, SE], + [E, NW, NW, NW]] + + # Restrict piece 4 + perms = (permute(p, idos[3]) for p in idos) + pieces = [[convert(pp) for pp in p] for p in perms] + return (board, cti, pieces) + + +def solve(n, i_min, free, curr_board, pieces_left, solutions, fps, se_nh, + # Hack to use a fast local variable to avoid a global lookup + bisect=bisect): + + fp_i_cands = fps[i_min] + for p in pieces_left: + fp_cands = fp_i_cands[p] + for fp in fp_cands: + if fp <= free: + n_curr_board = curr_board[:] + for ci in fp: + n_curr_board[ci] = p + + if len(pieces_left) > 1: + n_free = free - fp + n_i_min = min(n_free) + if len(n_free & se_nh[n_i_min]) > 0: + n_pieces_left = pieces_left[:] + n_pieces_left.remove(p) + solve(n, n_i_min, n_free, n_curr_board, + n_pieces_left, solutions, fps, se_nh) + else: + s = ''.join(map(str, n_curr_board)) + solutions.insert(bisect(solutions, s), s) + rs = s[::-1] + solutions.insert(bisect(solutions, rs), rs) + if len(solutions) >= n: + return + + if len(solutions) >= n: + return + + +def bench_meteor_contest(board, pieces, solve_arg, fps, se_nh): + free = frozenset(range(len(board))) + curr_board = [-1] * len(board) + pieces_left = list(range(len(pieces))) + solutions = [] + solve(solve_arg, 0, free, curr_board, pieces_left, + solutions, fps, se_nh) + + if solutions != SOLUTIONS: + raise ValueError("unexpected solutions") + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + board, cti, pieces = get_puzzle(WIDTH, HEIGHT) + fps = get_footprints(board, cti, pieces) + se_nh = get_senh(board, cti) + + solve_arg = SOLVE_ARG + bench_meteor_contest(board, pieces, solve_arg, fps, se_nh) + + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py b/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py new file mode 100644 index 00000000..1196db50 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py @@ -0,0 +1,165 @@ +""" +N-body benchmark from the Computer Language Benchmarks Game. + +This is intended to support Unladen Swallow's pyperf.py. Accordingly, it has been +modified from the Shootout version: +- Accept standard Unladen Swallow benchmark options. +- Run report_energy()/advance() in a loop. +- Reimplement itertools.combinations() to work with older Python versions. + +Pulled from: +http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=python3&id=1 + +Contributed by Kevin Carson. +Modified by Tupteq, Fredrik Johansson, and Daniel Nanz. +""" + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +__contact__ = "collinwinter@google.com (Collin Winter)" +DEFAULT_ITERATIONS = 20000 +DEFAULT_REFERENCE = 'sun' + + +def combinations(l): + """Pure-Python implementation of itertools.combinations(l, 2).""" + result = [] + for x in range(len(l) - 1): + ls = l[x + 1:] + for y in ls: + result.append((l[x], y)) + return result + + +PI = 3.14159265358979323 +SOLAR_MASS = 4 * PI * PI +DAYS_PER_YEAR = 365.24 + +BODIES = { + 'sun': ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], SOLAR_MASS), + + 'jupiter': ([4.84143144246472090e+00, + -1.16032004402742839e+00, + -1.03622044471123109e-01], + [1.66007664274403694e-03 * DAYS_PER_YEAR, + 7.69901118419740425e-03 * DAYS_PER_YEAR, + -6.90460016972063023e-05 * DAYS_PER_YEAR], + 9.54791938424326609e-04 * SOLAR_MASS), + + 'saturn': ([8.34336671824457987e+00, + 4.12479856412430479e+00, + -4.03523417114321381e-01], + [-2.76742510726862411e-03 * DAYS_PER_YEAR, + 4.99852801234917238e-03 * DAYS_PER_YEAR, + 2.30417297573763929e-05 * DAYS_PER_YEAR], + 2.85885980666130812e-04 * SOLAR_MASS), + + 'uranus': ([1.28943695621391310e+01, + -1.51111514016986312e+01, + -2.23307578892655734e-01], + [2.96460137564761618e-03 * DAYS_PER_YEAR, + 2.37847173959480950e-03 * DAYS_PER_YEAR, + -2.96589568540237556e-05 * DAYS_PER_YEAR], + 4.36624404335156298e-05 * SOLAR_MASS), + + 'neptune': ([1.53796971148509165e+01, + -2.59193146099879641e+01, + 1.79258772950371181e-01], + [2.68067772490389322e-03 * DAYS_PER_YEAR, + 1.62824170038242295e-03 * DAYS_PER_YEAR, + -9.51592254519715870e-05 * DAYS_PER_YEAR], + 5.15138902046611451e-05 * SOLAR_MASS)} + + +SYSTEM = list(BODIES.values()) +PAIRS = combinations(SYSTEM) + + +def advance(dt, n, bodies=SYSTEM, pairs=PAIRS): + for i in range(n): + for (([x1, y1, z1], v1, m1), + ([x2, y2, z2], v2, m2)) in pairs: + dx = x1 - x2 + dy = y1 - y2 + dz = z1 - z2 + mag = dt * ((dx * dx + dy * dy + dz * dz) ** (-1.5)) + b1m = m1 * mag + b2m = m2 * mag + v1[0] -= dx * b2m + v1[1] -= dy * b2m + v1[2] -= dz * b2m + v2[0] += dx * b1m + v2[1] += dy * b1m + v2[2] += dz * b1m + for (r, [vx, vy, vz], m) in bodies: + r[0] += dt * vx + r[1] += dt * vy + r[2] += dt * vz + + +def report_energy(bodies=SYSTEM, pairs=PAIRS, e=0.0): + for (((x1, y1, z1), v1, m1), + ((x2, y2, z2), v2, m2)) in pairs: + dx = x1 - x2 + dy = y1 - y2 + dz = z1 - z2 + e -= (m1 * m2) / ((dx * dx + dy * dy + dz * dz) ** 0.5) + for (r, [vx, vy, vz], m) in bodies: + e += m * (vx * vx + vy * vy + vz * vz) / 2. + return e + + +def offset_momentum(ref, bodies=SYSTEM, px=0.0, py=0.0, pz=0.0): + for (r, [vx, vy, vz], m) in bodies: + px -= vx * m + py -= vy * m + pz -= vz * m + (r, v, m) = ref + v[0] = px / m + v[1] = py / m + v[2] = pz / m + + +def bench_nbody(reference, iterations): + # Set up global state + offset_momentum(BODIES[reference]) + + report_energy() + advance(0.01, iterations) + report_energy() + + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--iterations", + type=int, default=DEFAULT_ITERATIONS, + help="Number of nbody advance() iterations " + "(default: %s)" % DEFAULT_ITERATIONS) + parser.add_argument("--reference", + type=str, default=DEFAULT_REFERENCE, + help="nbody reference (default: %s)" + % DEFAULT_REFERENCE) + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_nbody(args.reference, args.iterations) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py b/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py new file mode 100644 index 00000000..e7b8bc39 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py @@ -0,0 +1,80 @@ +"""Simple, brute-force N-Queens solver.""" + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +__author__ = "collinwinter@google.com (Collin Winter)" + + +# Pure-Python implementation of itertools.permutations(). +def permutations(iterable, r=None): + """permutations(range(3), 2) --> (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)""" + pool = tuple(iterable) + n = len(pool) + if r is None: + r = n + indices = list(range(n)) + cycles = list(range(n - r + 1, n + 1))[::-1] + yield tuple(pool[i] for i in indices[:r]) + while n: + for i in reversed(range(r)): + cycles[i] -= 1 + if cycles[i] == 0: + indices[i:] = indices[i + 1:] + indices[i:i + 1] + cycles[i] = n - i + else: + j = cycles[i] + indices[i], indices[-j] = indices[-j], indices[i] + yield tuple(pool[i] for i in indices[:r]) + break + else: + return + + +# From http://code.activestate.com/recipes/576647/ +def n_queens(queen_count): + """N-Queens solver. + + Args: + queen_count: the number of queens to solve for. This is also the + board size. + + Yields: + Solutions to the problem. Each yielded value is looks like + (3, 8, 2, 1, 4, ..., 6) where each number is the column position for the + queen, and the index into the tuple indicates the row. + """ + cols = range(queen_count) + for vec in permutations(cols): + if (queen_count == len(set(vec[i] + i for i in cols)) + == len(set(vec[i] - i for i in cols))): + yield vec + + +def bench_n_queens(queen_count): + list(n_queens(queen_count)) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + queen_count = 8 + bench_n_queens(queen_count) + + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py new file mode 100644 index 00000000..a97b6e8d --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py @@ -0,0 +1,86 @@ +""" +Test the performance of pathlib operations. + +This benchmark stresses the creation of small objects, globbing, and system +calls. +""" + +# Python imports +import os +import pathlib +import shutil +import tempfile + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +NUM_FILES = 2000 + + +def generate_filenames(tmp_path, num_files): + i = 0 + while num_files: + for ext in [".py", ".txt", ".tar.gz", ""]: + i += 1 + yield os.path.join(tmp_path, str(i) + ext) + num_files -= 1 + + +def setup(num_files): + tmp_path = tempfile.mkdtemp() + for fn in generate_filenames(tmp_path, num_files): + with open(fn, "wb") as f: + f.write(b'benchmark') + + return tmp_path + + +def bench_pathlib(tmp_path): + base_path = pathlib.Path(tmp_path) + + # Warm up the filesystem cache and keep some objects in memory. + path_objects = list(base_path.iterdir()) + # FIXME: does this code really cache anything? + for p in path_objects: + p.stat() + assert len(path_objects) == NUM_FILES, len(path_objects) + + + # Do something simple with each path. + for p in base_path.iterdir(): + p.stat() + for p in base_path.glob("*.py"): + p.stat() + for p in base_path.iterdir(): + p.stat() + for p in base_path.glob("*.py"): + p.stat() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + tmp_path = setup(NUM_FILES) + try: + bench_pathlib(tmp_path) + finally: + shutil.rmtree(tmp_path) + + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py new file mode 100644 index 00000000..f1d7e05f --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py @@ -0,0 +1,305 @@ + +"""Script for testing the performance of pickling/unpickling. + +This will pickle/unpickle several real world-representative objects a few +thousand times. The methodology below was chosen for was chosen to be similar +to real-world scenarios which operate on single objects at a time. Note that if +we did something like + + pickle.dumps([dict(some_dict) for _ in range(10000)]) + +this isn't equivalent to dumping the dict 10000 times: pickle uses a +highly-efficient encoding for the n-1 following copies. +""" + +import datetime +import random +import sys + +import pyperf + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +IS_PYPY = (pyperf.python_implementation() == 'pypy') + +__author__ = "collinwinter@google.com (Collin Winter)" + + +DICT = { + 'ads_flags': 0, + 'age': 18, + 'birthday': datetime.date(1980, 5, 7), + 'bulletin_count': 0, + 'comment_count': 0, + 'country': 'BR', + 'encrypted_id': 'G9urXXAJwjE', + 'favorite_count': 9, + 'first_name': '', + 'flags': 412317970704, + 'friend_count': 0, + 'gender': 'm', + 'gender_for_display': 'Male', + 'id': 302935349, + 'is_custom_profile_icon': 0, + 'last_name': '', + 'locale_preference': 'pt_BR', + 'member': 0, + 'tags': ['a', 'b', 'c', 'd', 'e', 'f', 'g'], + 'profile_foo_id': 827119638, + 'secure_encrypted_id': 'Z_xxx2dYx3t4YAdnmfgyKw', + 'session_number': 2, + 'signup_id': '201-19225-223', + 'status': 'A', + 'theme': 1, + 'time_created': 1225237014, + 'time_updated': 1233134493, + 'unread_message_count': 0, + 'user_group': '0', + 'username': 'collinwinter', + 'play_count': 9, + 'view_count': 7, + 'zip': ''} + +TUPLE = ( + [265867233, 265868503, 265252341, 265243910, 265879514, + 266219766, 266021701, 265843726, 265592821, 265246784, + 265853180, 45526486, 265463699, 265848143, 265863062, + 265392591, 265877490, 265823665, 265828884, 265753032], 60) + + +def mutate_dict(orig_dict, random_source): + new_dict = dict(orig_dict) + for key, value in new_dict.items(): + rand_val = random_source.random() * sys.maxsize + if isinstance(key, (int, bytes, str)): + new_dict[key] = type(key)(rand_val) + return new_dict + + +random_source = random.Random(5) # Fixed seed. +DICT_GROUP = [mutate_dict(DICT, random_source) for _ in range(3)] + + +def bench_pickle(loops, pickle, options): + range_it = range(loops) + + # micro-optimization: use fast local variables + dumps = pickle.dumps + objs = (DICT, TUPLE, DICT_GROUP) + protocol = options.protocol + t0 = pyperf.perf_counter() + + for _ in range_it: + for obj in objs: + # 20 dumps + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + + return pyperf.perf_counter() - t0 + + +def bench_unpickle(loops, pickle, options): + pickled_dict = pickle.dumps(DICT, options.protocol) + pickled_tuple = pickle.dumps(TUPLE, options.protocol) + pickled_dict_group = pickle.dumps(DICT_GROUP, options.protocol) + range_it = range(loops) + + # micro-optimization: use fast local variables + loads = pickle.loads + objs = (pickled_dict, pickled_tuple, pickled_dict_group) + + t0 = pyperf.perf_counter() + for _ in range_it: + for obj in objs: + # 20 loads dict + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + loads(obj) + + return pyperf.perf_counter() - t0 + + +LIST = [[list(range(10)), list(range(10))] for _ in range(10)] + + +def bench_pickle_list(loops, pickle, options): + range_it = range(loops) + # micro-optimization: use fast local variables + dumps = pickle.dumps + obj = LIST + protocol = options.protocol + t0 = pyperf.perf_counter() + + for _ in range_it: + # 10 dumps list + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + dumps(obj, protocol) + + return pyperf.perf_counter() - t0 + + +def bench_unpickle_list(loops, pickle, options): + pickled_list = pickle.dumps(LIST, options.protocol) + range_it = range(loops) + + # micro-optimization: use fast local variables + loads = pickle.loads + t0 = pyperf.perf_counter() + + for _ in range_it: + # 10 loads list + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + loads(pickled_list) + + return pyperf.perf_counter() - t0 + + +MICRO_DICT = dict((key, dict.fromkeys(range(10))) for key in range(100)) + + +def bench_pickle_dict(loops, pickle, options): + range_it = range(loops) + # micro-optimization: use fast local variables + protocol = options.protocol + obj = MICRO_DICT + t0 = pyperf.perf_counter() + + for _ in range_it: + # 5 dumps dict + pickle.dumps(obj, protocol) + pickle.dumps(obj, protocol) + pickle.dumps(obj, protocol) + pickle.dumps(obj, protocol) + pickle.dumps(obj, protocol) + + return pyperf.perf_counter() - t0 + + +BENCHMARKS = { + # 20 inner-loops: don't count the 3 pickled objects + 'pickle': (bench_pickle, 20), + + # 20 inner-loops: don't count the 3 unpickled objects + 'unpickle': (bench_unpickle, 20), + + 'pickle_list': (bench_pickle_list, 10), + 'unpickle_list': (bench_unpickle_list, 10), + 'pickle_dict': (bench_pickle_dict, 5), +} + + +def is_accelerated_module(module): + return getattr(pickle.Pickler, '__module__', '') != 'pickle' + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--pure-python", + action="store_true", + help="Use the C version of pickle.") + parser.add_argument("--protocol", + action="store", + default=None, + type=int, + help="Which protocol to use (default: highest protocol).") + benchmarks = sorted(BENCHMARKS) + + options = parser.parse_args() + + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if not (options.pure_python or IS_PYPY): + # C accelerators are enabled by default on 3.x + import pickle + if not is_accelerated_module(pickle): + raise RuntimeError("Missing C accelerators for pickle") + else: + sys.modules['_pickle'] = None + import pickle + if is_accelerated_module(pickle): + raise RuntimeError("Unexpected C accelerators for pickle") + + if options.protocol is None: + options.protocol = pickle.HIGHEST_PROTOCOL + + + for benchmark, inner_loops in BENCHMARKS.values(): + benchmark(inner_loops, pickle, options) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py new file mode 100644 index 00000000..05b804c4 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py @@ -0,0 +1,87 @@ +# coding: utf-8 +""" +Calculating some of the digits of π. + +This benchmark stresses big integer arithmetic. + +Adapted from code on: +http://benchmarksgame.alioth.debian.org/ +""" + +import itertools + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DEFAULT_DIGITS = 2000 +icount = itertools.count +islice = itertools.islice + + +def gen_x(): + return map(lambda k: (k, 4 * k + 2, 0, 2 * k + 1), icount(1)) + + +def compose(a, b): + aq, ar, as_, at = a + bq, br, bs, bt = b + return (aq * bq, + aq * br + ar * bt, + as_ * bq + at * bs, + as_ * br + at * bt) + + +def extract(z, j): + q, r, s, t = z + return (q * j + r) // (s * j + t) + + +def gen_pi_digits(): + z = (1, 0, 0, 1) + x = gen_x() + while 1: + y = extract(z, 3) + while y != extract(z, 4): + z = compose(z, next(x)) + y = extract(z, 3) + z = compose((10, -10 * y, 0, 1), z) + yield y + + +def calc_ndigits(n): + return list(islice(gen_pi_digits(), n)) + + +def add_cmdline_args(cmd, args): + cmd.extend(("--digits", str(args.digits))) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--digits", + type=int, + default=DEFAULT_DIGITS, + help="Number of computed pi digits (default: %s)" + % DEFAULT_DIGITS) + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + calc_ndigits(args.digits) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py new file mode 100755 index 00000000..606e6f87 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py @@ -0,0 +1,678 @@ +#!/usr/bin/env python +""" +Copyright 2006--2007-01-21 Paul Sladen +http://www.paul.sladen.org/projects/compression/ + +You may use and distribute this code under any DFSG-compatible +license (eg. BSD, GNU GPLv2). + +Stand-alone pure-Python DEFLATE (gzip) and bzip2 decoder/decompressor. +This is probably most useful for research purposes/index building; there +is certainly some room for improvement in the Huffman bit-matcher. + +With the as-written implementation, there was a known bug in BWT +decoding to do with repeated strings. This has been worked around; +see 'bwt_reverse()'. Correct output is produced in all test cases +but ideally the problem would be found... +""" + +import hashlib +import os +import struct + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +int2byte = struct.Struct(">B").pack + + +class BitfieldBase(object): + + def __init__(self, x): + if isinstance(x, BitfieldBase): + self.f = x.f + self.bits = x.bits + self.bitfield = x.bitfield + self.count = x.bitfield + else: + self.f = x + self.bits = 0 + self.bitfield = 0x0 + self.count = 0 + + def _read(self, n): + s = self.f.read(n) + if not s: + raise "Length Error" + self.count += len(s) + return s + + def needbits(self, n): + while self.bits < n: + self._more() + + def _mask(self, n): + return (1 << n) - 1 + + def toskip(self): + return self.bits & 0x7 + + def align(self): + self.readbits(self.toskip()) + + def dropbits(self, n=8): + while n >= self.bits and n > 7: + n -= self.bits + self.bits = 0 + n -= len(self.f._read(n >> 3)) << 3 + if n: + self.readbits(n) + # No return value + + def dropbytes(self, n=1): + self.dropbits(n << 3) + + def tell(self): + return self.count - ((self.bits + 7) >> 3), 7 - ((self.bits - 1) & 0x7) + + def tellbits(self): + bytes, bits = self.tell() + return (bytes << 3) + bits + + +class Bitfield(BitfieldBase): + + def _more(self): + c = self._read(1) + self.bitfield += ord(c) << self.bits + self.bits += 8 + + def snoopbits(self, n=8): + if n > self.bits: + self.needbits(n) + return self.bitfield & self._mask(n) + + def readbits(self, n=8): + if n > self.bits: + self.needbits(n) + r = self.bitfield & self._mask(n) + self.bits -= n + self.bitfield >>= n + return r + + +class RBitfield(BitfieldBase): + + def _more(self): + c = self._read(1) + self.bitfield <<= 8 + self.bitfield += ord(c) + self.bits += 8 + + def snoopbits(self, n=8): + if n > self.bits: + self.needbits(n) + return (self.bitfield >> (self.bits - n)) & self._mask(n) + + def readbits(self, n=8): + if n > self.bits: + self.needbits(n) + r = (self.bitfield >> (self.bits - n)) & self._mask(n) + self.bits -= n + self.bitfield &= ~(self._mask(n) << self.bits) + return r + + +def printbits(v, n): + o = '' + for i in range(n): + if v & 1: + o = '1' + o + else: + o = '0' + o + v >>= 1 + return o + + +class HuffmanLength(object): + + def __init__(self, code, bits=0): + self.code = code + self.bits = bits + self.symbol = None + self.reverse_symbol = None + + def __repr__(self): + return repr((self.code, self.bits, self.symbol, self.reverse_symbol)) + + @staticmethod + def _sort_func(obj): + return (obj.bits, obj.code) + + +def reverse_bits(v, n): + a = 1 << 0 + b = 1 << (n - 1) + z = 0 + for i in range(n - 1, -1, -2): + z |= (v >> i) & a + z |= (v << i) & b + a <<= 1 + b >>= 1 + return z + + +def reverse_bytes(v, n): + a = 0xff << 0 + b = 0xff << (n - 8) + z = 0 + for i in range(n - 8, -8, -16): + z |= (v >> i) & a + z |= (v << i) & b + a <<= 8 + b >>= 8 + return z + + +class HuffmanTable(object): + + def __init__(self, bootstrap): + l = [] + start, bits = bootstrap[0] + for finish, endbits in bootstrap[1:]: + if bits: + for code in range(start, finish): + l.append(HuffmanLength(code, bits)) + start, bits = finish, endbits + if endbits == -1: + break + l.sort(key=HuffmanLength._sort_func) + self.table = l + + def populate_huffman_symbols(self): + bits, symbol = -1, -1 + for x in self.table: + symbol += 1 + if x.bits != bits: + symbol <<= (x.bits - bits) + bits = x.bits + x.symbol = symbol + x.reverse_symbol = reverse_bits(symbol, bits) + + def tables_by_bits(self): + d = {} + for x in self.table: + try: + d[x.bits].append(x) + except: # noqa + d[x.bits] = [x] + + def min_max_bits(self): + self.min_bits, self.max_bits = 16, -1 + for x in self.table: + if x.bits < self.min_bits: + self.min_bits = x.bits + if x.bits > self.max_bits: + self.max_bits = x.bits + + def _find_symbol(self, bits, symbol, table): + for h in table: + if h.bits == bits and h.reverse_symbol == symbol: + return h.code + return -1 + + def find_next_symbol(self, field, reversed=True): + cached_length = -1 + cached = None + for x in self.table: + if cached_length != x.bits: + cached = field.snoopbits(x.bits) + cached_length = x.bits + if (reversed and x.reverse_symbol == cached) or (not reversed and x.symbol == cached): + field.readbits(x.bits) + return x.code + raise Exception("unfound symbol, even after end of table @%r" + % field.tell()) + + for bits in range(self.min_bits, self.max_bits + 1): + r = self._find_symbol(bits, field.snoopbits(bits), self.table) + if 0 <= r: + field.readbits(bits) + return r + elif bits == self.max_bits: + raise "unfound symbol, even after max_bits" + + +class OrderedHuffmanTable(HuffmanTable): + + def __init__(self, lengths): + l = len(lengths) + z = list(zip(range(l), lengths)) + [(l, -1)] + HuffmanTable.__init__(self, z) + + +def code_length_orders(i): + return (16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, + 13, 2, 14, 1, 15)[i] + + +def distance_base(i): + return (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, + 12289, 16385, 24577)[i] + + +def length_base(i): + return (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, + 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258)[i - 257] + + +def extra_distance_bits(n): + if 0 <= n <= 1: + return 0 + elif 2 <= n <= 29: + return (n >> 1) - 1 + else: + raise "illegal distance code" + + +def extra_length_bits(n): + if 257 <= n <= 260 or n == 285: + return 0 + elif 261 <= n <= 284: + return ((n - 257) >> 2) - 1 + else: + raise "illegal length code" + + +def move_to_front(l, c): + l[:] = l[c:c + 1] + l[0:c] + l[c + 1:] + + +def bwt_transform(L): + # Semi-inefficient way to get the character counts + F = bytes(sorted(L)) + base = [] + for i in range(256): + base.append(F.find(int2byte(i))) + + pointers = [-1] * len(L) + for i, symbol in enumerate(L): + pointers[base[symbol]] = i + base[symbol] += 1 + return pointers + + +def bwt_reverse(L, end): + out = [] + if len(L): + T = bwt_transform(L) + + # STRAGENESS WARNING: There was a bug somewhere here in that + # if the output of the BWT resolves to a perfect copy of N + # identical strings (think exact multiples of 255 'X' here), + # then a loop is formed. When decoded, the output string would + # be cut off after the first loop, typically '\0\0\0\0\xfb'. + # The previous loop construct was: + # + # next = T[end] + # while next != end: + # out += L[next] + # next = T[next] + # out += L[next] + # + # For the moment, I've instead replaced it with a check to see + # if there has been enough output generated. I didn't figured + # out where the off-by-one-ism is yet---that actually produced + # the cyclic loop. + + for i in range(len(L)): + end = T[end] + out.append(L[end]) + + return bytes(out) + + +def compute_used(b): + huffman_used_map = b.readbits(16) + map_mask = 1 << 15 + used = [] + while map_mask > 0: + if huffman_used_map & map_mask: + huffman_used_bitmap = b.readbits(16) + bit_mask = 1 << 15 + while bit_mask > 0: + if huffman_used_bitmap & bit_mask: + pass + used += [bool(huffman_used_bitmap & bit_mask)] + bit_mask >>= 1 + else: + used += [False] * 16 + map_mask >>= 1 + return used + + +def compute_selectors_list(b, huffman_groups): + selectors_used = b.readbits(15) + mtf = list(range(huffman_groups)) + selectors_list = [] + for i in range(selectors_used): + # zero-terminated bit runs (0..62) of MTF'ed huffman table + c = 0 + while b.readbits(1): + c += 1 + if c >= huffman_groups: + raise "Bzip2 chosen selector greater than number of groups (max 6)" + if c >= 0: + move_to_front(mtf, c) + selectors_list.append(mtf[0]) + return selectors_list + + +def compute_tables(b, huffman_groups, symbols_in_use): + groups_lengths = [] + for j in range(huffman_groups): + length = b.readbits(5) + lengths = [] + for i in range(symbols_in_use): + if not 0 <= length <= 20: + raise "Bzip2 Huffman length code outside range 0..20" + while b.readbits(1): + length -= (b.readbits(1) * 2) - 1 + lengths += [length] + groups_lengths += [lengths] + + tables = [] + for g in groups_lengths: + codes = OrderedHuffmanTable(g) + codes.populate_huffman_symbols() + codes.min_max_bits() + tables.append(codes) + return tables + + +def decode_huffman_block(b, out): + randomised = b.readbits(1) + if randomised: + raise "Bzip2 randomised support not implemented" + pointer = b.readbits(24) + used = compute_used(b) + + huffman_groups = b.readbits(3) + if not 2 <= huffman_groups <= 6: + raise Exception("Bzip2: Number of Huffman groups not in range 2..6") + + selectors_list = compute_selectors_list(b, huffman_groups) + symbols_in_use = sum(used) + 2 # remember RUN[AB] RLE symbols + tables = compute_tables(b, huffman_groups, symbols_in_use) + + favourites = [int2byte(i) for i, x in enumerate(used) if x] + + selector_pointer = 0 + decoded = 0 + # Main Huffman loop + repeat = repeat_power = 0 + buffer = [] + t = None + while True: + decoded -= 1 + if decoded <= 0: + decoded = 50 # Huffman table re-evaluate/switch length + if selector_pointer <= len(selectors_list): + t = tables[selectors_list[selector_pointer]] + selector_pointer += 1 + + r = t.find_next_symbol(b, False) + if 0 <= r <= 1: + if repeat == 0: + repeat_power = 1 + repeat += repeat_power << r + repeat_power <<= 1 + continue + elif repeat > 0: + # Remember kids: If there is only one repeated + # real symbol, it is encoded with *zero* Huffman + # bits and not output... so buffer[-1] doesn't work. + buffer.append(favourites[0] * repeat) + repeat = 0 + if r == symbols_in_use - 1: + break + else: + o = favourites[r - 1] + move_to_front(favourites, r - 1) + buffer.append(o) + pass + + nt = nearly_there = bwt_reverse(b"".join(buffer), pointer) + i = 0 + # Pointless/irritating run-length encoding step + while i < len(nearly_there): + if i < len(nearly_there) - 4 and nt[i] == nt[i + 1] == nt[i + 2] == nt[i + 3]: + out.append(nearly_there[i:i + 1] * (ord(nearly_there[i + 4:i + 5]) + 4)) + i += 5 + else: + out.append(nearly_there[i:i + 1]) + i += 1 + +# Sixteen bits of magic have been removed by the time we start decoding + + +def bzip2_main(input): + b = RBitfield(input) + + method = b.readbits(8) + if method != ord('h'): + raise Exception( + "Unknown (not type 'h'uffman Bzip2) compression method") + + blocksize = b.readbits(8) + if ord('1') <= blocksize <= ord('9'): + blocksize = blocksize - ord('0') + else: + raise Exception("Unknown (not size '0'-'9') Bzip2 blocksize") + + out = [] + while True: + blocktype = b.readbits(48) + b.readbits(32) # crc + if blocktype == 0x314159265359: # (pi) + decode_huffman_block(b, out) + elif blocktype == 0x177245385090: # sqrt(pi) + b.align() + break + else: + raise Exception("Illegal Bzip2 blocktype") + return b''.join(out) + + +# Sixteen bits of magic have been removed by the time we start decoding +def gzip_main(field): + b = Bitfield(field) + method = b.readbits(8) + if method != 8: + raise Exception("Unknown (not type eight DEFLATE) compression method") + + # Use flags, drop modification time, extra flags and OS creator type. + flags = b.readbits(8) + b.readbits(32) # mtime + b.readbits(8) # extra_flags + b.readbits(8) # os_type + + if flags & 0x04: # structured GZ_FEXTRA miscellaneous data + xlen = b.readbits(16) + b.dropbytes(xlen) + while flags & 0x08: # original GZ_FNAME filename + if not b.readbits(8): + break + while flags & 0x10: # human readable GZ_FCOMMENT + if not b.readbits(8): + break + if flags & 0x02: # header-only GZ_FHCRC checksum + b.readbits(16) + + out = [] + while True: + lastbit = b.readbits(1) + blocktype = b.readbits(2) + + if blocktype == 0: + b.align() + length = b.readbits(16) + if length & b.readbits(16): + raise Exception("stored block lengths do not match each other") + for i in range(length): + out.append(int2byte(b.readbits(8))) + + elif blocktype == 1 or blocktype == 2: # Huffman + main_literals, main_distances = None, None + + if blocktype == 1: # Static Huffman + static_huffman_bootstrap = [ + (0, 8), (144, 9), (256, 7), (280, 8), (288, -1)] + static_huffman_lengths_bootstrap = [(0, 5), (32, -1)] + main_literals = HuffmanTable(static_huffman_bootstrap) + main_distances = HuffmanTable(static_huffman_lengths_bootstrap) + + elif blocktype == 2: # Dynamic Huffman + literals = b.readbits(5) + 257 + distances = b.readbits(5) + 1 + code_lengths_length = b.readbits(4) + 4 + + l = [0] * 19 + for i in range(code_lengths_length): + l[code_length_orders(i)] = b.readbits(3) + + dynamic_codes = OrderedHuffmanTable(l) + dynamic_codes.populate_huffman_symbols() + dynamic_codes.min_max_bits() + + # Decode the code_lengths for both tables at once, + # then split the list later + + code_lengths = [] + n = 0 + while n < (literals + distances): + r = dynamic_codes.find_next_symbol(b) + if 0 <= r <= 15: # literal bitlength for this code + count = 1 + what = r + elif r == 16: # repeat last code + count = 3 + b.readbits(2) + # Is this supposed to default to '0' if in the zeroth + # position? + what = code_lengths[-1] + elif r == 17: # repeat zero + count = 3 + b.readbits(3) + what = 0 + elif r == 18: # repeat zero lots + count = 11 + b.readbits(7) + what = 0 + else: + raise Exception( + "next code length is outside of the range 0 <= r <= 18") + code_lengths += [what] * count + n += count + + main_literals = OrderedHuffmanTable(code_lengths[:literals]) + main_distances = OrderedHuffmanTable(code_lengths[literals:]) + + # Common path for both Static and Dynamic Huffman decode now + + main_literals.populate_huffman_symbols() + main_distances.populate_huffman_symbols() + + main_literals.min_max_bits() + main_distances.min_max_bits() + + literal_count = 0 + while True: + r = main_literals.find_next_symbol(b) + if 0 <= r <= 255: + literal_count += 1 + out.append(int2byte(r)) + elif r == 256: + if literal_count > 0: + literal_count = 0 + break + elif 257 <= r <= 285: # dictionary lookup + if literal_count > 0: + literal_count = 0 + length_extra = b.readbits(extra_length_bits(r)) + length = length_base(r) + length_extra + + r1 = main_distances.find_next_symbol(b) + if 0 <= r1 <= 29: + distance = distance_base( + r1) + b.readbits(extra_distance_bits(r1)) + while length > distance: + out += out[-distance:] + length -= distance + if length == distance: + out += out[-distance:] + else: + out += out[-distance:length - distance] + elif 30 <= r1 <= 31: + raise Exception("illegal unused distance symbol " + "in use @%r" % b.tell()) + elif 286 <= r <= 287: + raise Exception("illegal unused literal/length symbol " + "in use @%r" % b.tell()) + elif blocktype == 3: + raise Exception("illegal unused blocktype in use @%r" % b.tell()) + + if lastbit: + break + + b.align() + b.readbits(32) # crc + b.readbits(32) # final_length + return "".join(out) + + +def bench_pyflake(filename): + input_fp = open(filename, 'rb') + + input_fp.seek(0) + field = RBitfield(input_fp) + + magic = field.readbits(16) + if magic == 0x1f8b: # GZip + out = gzip_main(field) + elif magic == 0x425a: # BZip2 + out = bzip2_main(field) + else: + raise Exception("Unknown file magic %x, not a gzip/bzip2 file" + % hex(magic)) + + input_fp.close() + + if hashlib.md5(out).hexdigest() != "afa004a630fe072901b1d9628b960974": + raise Exception("MD5 checksum mismatch") + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + filename = os.path.join(os.path.dirname(__file__), + "data", "interpreter.tar.bz2") + bench_pyflake(filename) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py b/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py new file mode 100644 index 00000000..fa78532f --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py @@ -0,0 +1,51 @@ +""" +Benchmark Python startup. +""" +import sys +import subprocess + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--no-site", + action="store_true") + parser.add_argument("--exit", + action="store_true") + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if args.no_site: + name += "_no_site" + if args.exit: + name += "_exit" + + command = [sys.executable] + if args.no_site: + command.append("-S") + if args.exit: + command.extend(("-c", "import os; os._exit(0)")) + else: + command.extend(("-c", "pass")) + + subprocess.run(command) + profiler.disable() + profiler.dump_stats("test.prof") + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py b/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py new file mode 100644 index 00000000..7fc147b0 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py @@ -0,0 +1,411 @@ +""" +This file contains definitions for a simple raytracer. +Copyright Callum and Tony Garnock-Jones, 2008. + +This file may be freely redistributed under the MIT license, +http://www.opensource.org/licenses/mit-license.php + +From http://www.lshift.net/blog/2008/10/29/toy-raytracer-in-python +""" + +import array +import math + + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DEFAULT_WIDTH = 100 +DEFAULT_HEIGHT = 100 +EPSILON = 0.00001 + + +class Vector(object): + + def __init__(self, initx, inity, initz): + self.x = initx + self.y = inity + self.z = initz + + def __str__(self): + return '(%s,%s,%s)' % (self.x, self.y, self.z) + + def __repr__(self): + return 'Vector(%s,%s,%s)' % (self.x, self.y, self.z) + + def magnitude(self): + return math.sqrt(self.dot(self)) + + def __add__(self, other): + if other.isPoint(): + return Point(self.x + other.x, self.y + other.y, self.z + other.z) + else: + return Vector(self.x + other.x, self.y + other.y, self.z + other.z) + + def __sub__(self, other): + other.mustBeVector() + return Vector(self.x - other.x, self.y - other.y, self.z - other.z) + + def scale(self, factor): + return Vector(factor * self.x, factor * self.y, factor * self.z) + + def dot(self, other): + other.mustBeVector() + return (self.x * other.x) + (self.y * other.y) + (self.z * other.z) + + def cross(self, other): + other.mustBeVector() + return Vector(self.y * other.z - self.z * other.y, + self.z * other.x - self.x * other.z, + self.x * other.y - self.y * other.x) + + def normalized(self): + return self.scale(1.0 / self.magnitude()) + + def negated(self): + return self.scale(-1) + + def __eq__(self, other): + return (self.x == other.x) and (self.y == other.y) and (self.z == other.z) + + def isVector(self): + return True + + def isPoint(self): + return False + + def mustBeVector(self): + return self + + def mustBePoint(self): + raise 'Vectors are not points!' + + def reflectThrough(self, normal): + d = normal.scale(self.dot(normal)) + return self - d.scale(2) + + +Vector.ZERO = Vector(0, 0, 0) +Vector.RIGHT = Vector(1, 0, 0) +Vector.UP = Vector(0, 1, 0) +Vector.OUT = Vector(0, 0, 1) + +assert Vector.RIGHT.reflectThrough(Vector.UP) == Vector.RIGHT +assert Vector(-1, -1, 0).reflectThrough(Vector.UP) == Vector(-1, 1, 0) + + +class Point(object): + + def __init__(self, initx, inity, initz): + self.x = initx + self.y = inity + self.z = initz + + def __str__(self): + return '(%s,%s,%s)' % (self.x, self.y, self.z) + + def __repr__(self): + return 'Point(%s,%s,%s)' % (self.x, self.y, self.z) + + def __add__(self, other): + other.mustBeVector() + return Point(self.x + other.x, self.y + other.y, self.z + other.z) + + def __sub__(self, other): + if other.isPoint(): + return Vector(self.x - other.x, self.y - other.y, self.z - other.z) + else: + return Point(self.x - other.x, self.y - other.y, self.z - other.z) + + def isVector(self): + return False + + def isPoint(self): + return True + + def mustBeVector(self): + raise 'Points are not vectors!' + + def mustBePoint(self): + return self + + +class Sphere(object): + + def __init__(self, centre, radius): + centre.mustBePoint() + self.centre = centre + self.radius = radius + + def __repr__(self): + return 'Sphere(%s,%s)' % (repr(self.centre), self.radius) + + def intersectionTime(self, ray): + cp = self.centre - ray.point + v = cp.dot(ray.vector) + discriminant = (self.radius * self.radius) - (cp.dot(cp) - v * v) + if discriminant < 0: + return None + else: + return v - math.sqrt(discriminant) + + def normalAt(self, p): + return (p - self.centre).normalized() + + +class Halfspace(object): + + def __init__(self, point, normal): + self.point = point + self.normal = normal.normalized() + + def __repr__(self): + return 'Halfspace(%s,%s)' % (repr(self.point), repr(self.normal)) + + def intersectionTime(self, ray): + v = ray.vector.dot(self.normal) + if v: + return 1 / -v + else: + return None + + def normalAt(self, p): + return self.normal + + +class Ray(object): + + def __init__(self, point, vector): + self.point = point + self.vector = vector.normalized() + + def __repr__(self): + return 'Ray(%s,%s)' % (repr(self.point), repr(self.vector)) + + def pointAtTime(self, t): + return self.point + self.vector.scale(t) + + +Point.ZERO = Point(0, 0, 0) + + +class Canvas(object): + + def __init__(self, width, height): + self.bytes = array.array('B', [0] * (width * height * 3)) + for i in range(width * height): + self.bytes[i * 3 + 2] = 255 + self.width = width + self.height = height + + def plot(self, x, y, r, g, b): + i = ((self.height - y - 1) * self.width + x) * 3 + self.bytes[i] = max(0, min(255, int(r * 255))) + self.bytes[i + 1] = max(0, min(255, int(g * 255))) + self.bytes[i + 2] = max(0, min(255, int(b * 255))) + + def write_ppm(self, filename): + header = 'P6 %d %d 255\n' % (self.width, self.height) + with open(filename, "wb") as fp: + fp.write(header.encode('ascii')) + fp.write(self.bytes.tostring()) + + +def firstIntersection(intersections): + result = None + for i in intersections: + candidateT = i[1] + if candidateT is not None and candidateT > -EPSILON: + if result is None or candidateT < result[1]: + result = i + return result + + +class Scene(object): + + def __init__(self): + self.objects = [] + self.lightPoints = [] + self.position = Point(0, 1.8, 10) + self.lookingAt = Point.ZERO + self.fieldOfView = 45 + self.recursionDepth = 0 + + def moveTo(self, p): + self.position = p + + def lookAt(self, p): + self.lookingAt = p + + def addObject(self, object, surface): + self.objects.append((object, surface)) + + def addLight(self, p): + self.lightPoints.append(p) + + def render(self, canvas): + fovRadians = math.pi * (self.fieldOfView / 2.0) / 180.0 + halfWidth = math.tan(fovRadians) + halfHeight = 0.75 * halfWidth + width = halfWidth * 2 + height = halfHeight * 2 + pixelWidth = width / (canvas.width - 1) + pixelHeight = height / (canvas.height - 1) + + eye = Ray(self.position, self.lookingAt - self.position) + vpRight = eye.vector.cross(Vector.UP).normalized() + vpUp = vpRight.cross(eye.vector).normalized() + + for y in range(canvas.height): + for x in range(canvas.width): + xcomp = vpRight.scale(x * pixelWidth - halfWidth) + ycomp = vpUp.scale(y * pixelHeight - halfHeight) + ray = Ray(eye.point, eye.vector + xcomp + ycomp) + colour = self.rayColour(ray) + canvas.plot(x, y, *colour) + + def rayColour(self, ray): + if self.recursionDepth > 3: + return (0, 0, 0) + try: + self.recursionDepth = self.recursionDepth + 1 + intersections = [(o, o.intersectionTime(ray), s) + for (o, s) in self.objects] + i = firstIntersection(intersections) + if i is None: + return (0, 0, 0) # the background colour + else: + (o, t, s) = i + p = ray.pointAtTime(t) + return s.colourAt(self, ray, p, o.normalAt(p)) + finally: + self.recursionDepth = self.recursionDepth - 1 + + def _lightIsVisible(self, l, p): + for (o, s) in self.objects: + t = o.intersectionTime(Ray(p, l - p)) + if t is not None and t > EPSILON: + return False + return True + + def visibleLights(self, p): + result = [] + for l in self.lightPoints: + if self._lightIsVisible(l, p): + result.append(l) + return result + + +def addColours(a, scale, b): + return (a[0] + scale * b[0], + a[1] + scale * b[1], + a[2] + scale * b[2]) + + +class SimpleSurface(object): + + def __init__(self, **kwargs): + self.baseColour = kwargs.get('baseColour', (1, 1, 1)) + self.specularCoefficient = kwargs.get('specularCoefficient', 0.2) + self.lambertCoefficient = kwargs.get('lambertCoefficient', 0.6) + self.ambientCoefficient = 1.0 - self.specularCoefficient - self.lambertCoefficient + + def baseColourAt(self, p): + return self.baseColour + + def colourAt(self, scene, ray, p, normal): + b = self.baseColourAt(p) + + c = (0, 0, 0) + if self.specularCoefficient > 0: + reflectedRay = Ray(p, ray.vector.reflectThrough(normal)) + reflectedColour = scene.rayColour(reflectedRay) + c = addColours(c, self.specularCoefficient, reflectedColour) + + if self.lambertCoefficient > 0: + lambertAmount = 0 + for lightPoint in scene.visibleLights(p): + contribution = (lightPoint - p).normalized().dot(normal) + if contribution > 0: + lambertAmount = lambertAmount + contribution + lambertAmount = min(1, lambertAmount) + c = addColours(c, self.lambertCoefficient * lambertAmount, b) + + if self.ambientCoefficient > 0: + c = addColours(c, self.ambientCoefficient, b) + + return c + + +class CheckerboardSurface(SimpleSurface): + + def __init__(self, **kwargs): + SimpleSurface.__init__(self, **kwargs) + self.otherColour = kwargs.get('otherColour', (0, 0, 0)) + self.checkSize = kwargs.get('checkSize', 1) + + def baseColourAt(self, p): + v = p - Point.ZERO + v.scale(1.0 / self.checkSize) + if ((int(abs(v.x) + 0.5) + + int(abs(v.y) + 0.5) + + int(abs(v.z) + 0.5)) % 2): + return self.otherColour + else: + return self.baseColour + + +def bench_raytrace( width, height, filename): + canvas = Canvas(width, height) + s = Scene() + s.addLight(Point(30, 30, 10)) + s.addLight(Point(-10, 100, 30)) + s.lookAt(Point(0, 3, 0)) + s.addObject(Sphere(Point(1, 3, -10), 2), + SimpleSurface(baseColour=(1, 1, 0))) + for y in range(6): + s.addObject(Sphere(Point(-3 - y * 0.4, 2.3, -5), 0.4), + SimpleSurface(baseColour=(y / 6.0, 1 - y / 6.0, 0.5))) + s.addObject(Halfspace(Point(0, 0, 0), Vector.UP), + CheckerboardSurface()) + s.render(canvas) + + if filename: + canvas.write_ppm(filename) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--width", + type=int, + default=DEFAULT_WIDTH, + help="Image width (default: %s)" % DEFAULT_WIDTH) + parser.add_argument("--height", + type=int, + default=DEFAULT_HEIGHT, + help="Image height (default: %s)" % DEFAULT_HEIGHT) + parser.add_argument("--filename", + metavar="FILENAME.PPM", + help="Output filename of the PPM picture") + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_raytrace(args.width, args.height, args.filename) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py new file mode 100644 index 00000000..73bf8ddc --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py @@ -0,0 +1,80 @@ + +"""Benchmark how quickly Python's regex implementation can compile regexes. + +We bring in all the regexes used by the other regex benchmarks, capture them by +stubbing out the re module, then compile those regexes repeatedly. We muck with +the re module's caching to force it to recompile every regex we give it. +""" + +# Python imports +import re + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +def capture_regexes(): + regexes = [] + + real_compile = re.compile + real_search = re.search + real_sub = re.sub + + def capture_compile(regex, flags=0): + regexes.append((regex, flags)) + return real_compile(regex, flags) + + def capture_search(regex, target, flags=0): + regexes.append((regex, flags)) + return real_search(regex, target, flags) + + def capture_sub(regex, *args): + regexes.append((regex, 0)) + return real_sub(regex, *args) + + re.compile = capture_compile + re.search = capture_search + re.sub = capture_sub + try: + import bm_regex_effbot + bm_regex_effbot.bench_regex_effbot(1) + + import bm_regex_v8 + bm_regex_v8.bench_regex_v8(1) + finally: + re.compile = real_compile + re.search = real_search + re.sub = real_sub + return regexes + + +def bench_regex_compile(regexes): + for regex, flags in regexes: + re.purge() + # ignore result (compiled regex) + re.compile(regex, flags) + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + regexes = capture_regexes() + bench_regex_compile(regexes) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py new file mode 100644 index 00000000..742a6e40 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py @@ -0,0 +1,240 @@ +#!/usr/bin/env python +""" +The Computer Language Benchmarks Game +http://benchmarksgame.alioth.debian.org/ + +regex-dna Python 3 #5 program: +contributed by Dominique Wahli +2to3 +modified by Justin Peel + +fasta Python 3 #3 program: +modified by Ian Osgood +modified again by Heinrich Acker +modified by Justin Peel +Modified by Christopher Sean Forgeron +""" + +import bisect +import re + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DEFAULT_INIT_LEN = 100000 +DEFAULT_RNG_SEED = 42 + +ALU = ('GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG' + 'GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA' + 'CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT' + 'ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA' + 'GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG' + 'AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC' + 'AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA') + +IUB = list(zip('acgtBDHKMNRSVWY', [0.27, 0.12, 0.12, 0.27] + [0.02] * 11)) + +HOMOSAPIENS = [ + ('a', 0.3029549426680), + ('c', 0.1979883004921), + ('g', 0.1975473066391), + ('t', 0.3015094502008), +] + + +def make_cumulative(table): + P = [] + C = [] + prob = 0. + for char, p in table: + prob += p + P += [prob] + C += [ord(char)] + return (P, C) + + +def repeat_fasta(src, n, nprint): + width = 60 + + is_trailing_line = False + count_modifier = 0.0 + + len_of_src = len(src) + ss = src + src + src[:n % len_of_src] + # CSF - It's faster to work with a bytearray than a string + s = bytearray(ss, encoding='utf8') + + if n % width: + # We don't end on a 60 char wide line + is_trailing_line = True + count_modifier = 1.0 + + # CSF - Here we are stuck with using an int instead of a float for the loop, + # but testing showed it still to be faster than a for loop + count = 0 + end = (n / float(width)) - count_modifier + while count < end: + i = count * 60 % len_of_src + nprint(s[i:i + 60] + b'\n') + count += 1 + if is_trailing_line: + nprint(s[-(n % width):] + b'\n') + + +def random_fasta(table, n, seed, nprint): + width = 60 + r = range(width) + bb = bisect.bisect + + # If we don't have a multiple of the width, then we will have a trailing + # line, which needs a slightly different approach + is_trailing_line = False + count_modifier = 0.0 + + line = bytearray(width + 1) # Width of 60 + 1 for the \n char + + probs, chars = make_cumulative(table) + + # pRNG Vars + im = 139968.0 + seed = float(seed) + + if n % width: + # We don't end on a 60 char wide line + is_trailing_line = True + count_modifier = 1.0 + + # CSF - Loops with a high iteration count run faster as a while/float loop. + count = 0.0 + end = (n / float(width)) - count_modifier + while count < end: + # CSF - Low iteration count loops may run faster as a for loop. + for i in r: + # CSF - Python is faster for all float math than it is for int, on my + # machine at least. + seed = (seed * 3877.0 + 29573.0) % 139968.0 + # CSF - While real values, not variables are faster for most things, on my + # machine, it's faster to have 'im' already in a var + line[i] = chars[bb(probs, seed / im)] + + line[60] = 10 # End of Line + nprint(line) + count += 1.0 + + if is_trailing_line: + for i in range(n % width): + seed = (seed * 3877.0 + 29573.0) % 139968.0 + line[i] = chars[bb(probs, seed / im)] + + nprint(line[:i + 1] + b"\n") + + return seed + + +def init_benchmarks(n, rng_seed): + result = bytearray() + nprint = result.extend + nprint(b'>ONE Homo sapiens alu\n') + repeat_fasta(ALU, n * 2, nprint=nprint) + + # We need to keep track of the state of 'seed' so we pass it in, and return + # it back so our output can pass the diff test + nprint(b'>TWO IUB ambiguity codes\n') + seed = random_fasta(IUB, n * 3, seed=rng_seed, nprint=nprint) + + nprint(b'>THREE Homo sapiens frequency\n') + random_fasta(HOMOSAPIENS, n * 5, seed, nprint=nprint) + + return bytes(result) + + +VARIANTS = ( + b'agggtaaa|tttaccct', + b'[cgt]gggtaaa|tttaccc[acg]', + b'a[act]ggtaaa|tttacc[agt]t', + b'ag[act]gtaaa|tttac[agt]ct', + b'agg[act]taaa|ttta[agt]cct', + b'aggg[acg]aaa|ttt[cgt]ccct', + b'agggt[cgt]aa|tt[acg]accct', + b'agggta[cgt]a|t[acg]taccct', + b'agggtaa[cgt]|[acg]ttaccct', +) + +SUBST = ( + (b'B', b'(c|g|t)'), (b'D', b'(a|g|t)'), (b'H', b'(a|c|t)'), + (b'K', b'(g|t)'), (b'M', b'(a|c)'), (b'N', b'(a|c|g|t)'), + (b'R', b'(a|g)'), (b'S', b'(c|g)'), (b'V', b'(a|c|g)'), + (b'W', b'(a|t)'), (b'Y', b'(c|t)'), +) + + +def run_benchmarks(seq): + ilen = len(seq) + + seq = re.sub(b'>.*\n|\n', b'', seq) + clen = len(seq) + + results = [] + for f in VARIANTS: + results.append(len(re.findall(f, seq))) + + for f, r in SUBST: + seq = re.sub(f, r, seq) + + return results, ilen, clen, len(seq) + + +def bench_regex_dna(seq, expected_res): + res = run_benchmarks(seq) + + if (expected_res is not None) and (res != expected_res): + raise Exception("run_benchmarks() error") + + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--fasta-length", + type=int, + default=DEFAULT_INIT_LEN, + help="Length of the fasta sequence " + "(default: %s)" % DEFAULT_INIT_LEN) + parser.add_argument("--rng-seed", + type=int, + default=DEFAULT_RNG_SEED, + help="Seed of the random number generator " + "(default: %s)" % DEFAULT_RNG_SEED) + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if args.fasta_length == 100000: + expected_len = 1016745 + expected_res = ([6, 26, 86, 58, 113, 31, 31, 32, 43], + 1016745, 1000000, 1336326) + else: + expected_len = None + expected_res = None + + seq = init_benchmarks(args.fasta_length, args.rng_seed) + if (expected_len is not None) and (len(seq) != expected_len): + raise Exception("init_benchmarks() error") + + bench_regex_dna(seq, expected_res) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py new file mode 100644 index 00000000..58aa5768 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py @@ -0,0 +1,183 @@ + +"""Benchmarks for Python's regex engine. + +These are some of the original benchmarks used to tune Python's regex engine +in 2000 written by Fredrik Lundh. Retreived from +http://mail.python.org/pipermail/python-dev/2000-August/007797.html and +integrated into Unladen Swallow's pyperf.py in 2009 by David Laing. + +These benchmarks are of interest since they helped to guide the original +optimization of the sre engine, and we shouldn't necessarily ignore them just +because they're "old". +""" + +# Python imports +import re + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +USE_BYTES = False + + +def re_compile(s): + if USE_BYTES: + return re.compile(s.encode('latin1')) + else: + return re.compile(s) + +# These are the regular expressions to be tested. These sync up, +# index-for-index with the list of strings generated by gen_string_table() +# below. + + +def gen_regex_table(): + return [ + re_compile('Python|Perl'), + re_compile('Python|Perl'), + re_compile('(Python|Perl)'), + re_compile('(?:Python|Perl)'), + re_compile('Python'), + re_compile('Python'), + re_compile('.*Python'), + re_compile('.*Python.*'), + re_compile('.*(Python)'), + re_compile('.*(?:Python)'), + re_compile('Python|Perl|Tcl'), + re_compile('Python|Perl|Tcl'), + re_compile('(Python|Perl|Tcl)'), + re_compile('(?:Python|Perl|Tcl)'), + re_compile('(Python)\\1'), + re_compile('(Python)\\1'), + re_compile('([0a-z][a-z0-9]*,)+'), + re_compile('(?:[0a-z][a-z0-9]*,)+'), + re_compile('([a-z][a-z0-9]*,)+'), + re_compile('(?:[a-z][a-z0-9]*,)+'), + re_compile('.*P.*y.*t.*h.*o.*n.*')] + + +def gen_string_table(n): + """Generates the list of strings that will be used in the benchmarks. + + All strings have repeated prefixes and suffices, and n specifies the + number of repetitions. + """ + strings = [] + + def append(s): + if USE_BYTES: + strings.append(s.encode('latin1')) + else: + strings.append(s) + append('-' * n + 'Perl' + '-' * n) + append('P' * n + 'Perl' + 'P' * n) + append('-' * n + 'Perl' + '-' * n) + append('-' * n + 'Perl' + '-' * n) + append('-' * n + 'Python' + '-' * n) + append('P' * n + 'Python' + 'P' * n) + append('-' * n + 'Python' + '-' * n) + append('-' * n + 'Python' + '-' * n) + append('-' * n + 'Python' + '-' * n) + append('-' * n + 'Python' + '-' * n) + append('-' * n + 'Perl' + '-' * n) + append('P' * n + 'Perl' + 'P' * n) + append('-' * n + 'Perl' + '-' * n) + append('-' * n + 'Perl' + '-' * n) + append('-' * n + 'PythonPython' + '-' * n) + append('P' * n + 'PythonPython' + 'P' * n) + append('-' * n + 'a5,b7,c9,' + '-' * n) + append('-' * n + 'a5,b7,c9,' + '-' * n) + append('-' * n + 'a5,b7,c9,' + '-' * n) + append('-' * n + 'a5,b7,c9,' + '-' * n) + append('-' * n + 'Python' + '-' * n) + return strings + + +def init_benchmarks(n_values=None): + """Initialize the strings we'll run the regexes against. + + The strings used in the benchmark are prefixed and suffixed by + strings that are repeated n times. + + The sequence n_values contains the values for n. + If n_values is None the values of n from the original benchmark + are used. + + The generated list of strings is cached in the string_tables + variable, which is indexed by n. + + Returns: + A list of string prefix/suffix lengths. + """ + + if n_values is None: + n_values = (0, 5, 50, 250, 1000, 5000, 10000) + + string_tables = {n: gen_string_table(n) for n in n_values} + regexs = gen_regex_table() + + data = [] + for n in n_values: + for id in range(len(regexs)): + regex = regexs[id] + string = string_tables[n][id] + data.append((regex, string)) + return data + + +def bench_regex_effbot(): + if bench_regex_effbot.data is None: + bench_regex_effbot.data = init_benchmarks() + data = bench_regex_effbot.data + + range_it = range(10) + search = re.search + + for _ in range_it: + # Runs all of the benchmarks for a given value of n. + for regex, string in data: + # search 10 times + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + search(regex, string) + + +# cached data, generated at the first call +bench_regex_effbot.data = None + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("-B", "--force_bytes", + action="store_true", + help="test bytes regexps") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if args.force_bytes: + USE_BYTES = True + + bench_regex_effbot() + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py new file mode 100644 index 00000000..80413fc9 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py @@ -0,0 +1,1806 @@ +# Copyright 2009 the V8 project authors. All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Automatically generated on 2009-01-30. + +# This benchmark is generated by loading 50 of the most popular pages +# on the web and logging all regexp operations performed. Each +# operation is given a weight that is calculated from an estimate of +# the popularity of the pages where it occurs and the number of times +# it is executed while loading each page. Finally the literal +# letters in the data are encoded using ROT13 in a way that does not +# affect how the regexps match their input. + + +# Ported to Python for Unladen Swallow. The original JS version can be found at +# https://github.com/v8/v8/blob/master/benchmarks/regexp.js, r1243. + +# Python imports +import re + +# Third party imports +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# The precompiled regexs that were in vars in the V8 code, split into +# tuples of (regex, flags). +compiled_regex_strings = [ + (r'^ba', ''), + (r'(((\w+):\/\/)([^\/:]*)(:(\d+))?)?([^#?]*)(\?([^#]*))?(#(.*))?', ''), + (r'^\s*|\s*$', 'g'), + (r'\bQBZPbageby_cynprubyqre\b', ''), + (r',', ''), + (r'\bQBZPbageby_cynprubyqre\b', 'g'), + (r'^[\s\xa0]+|[\s\xa0]+$', 'g'), + (r'(\d*)(\D*)', 'g'), + (r'=', ''), + (r'(^|\s)lhv\-h(\s|$)', ''), + (r'\#', 'g'), + (r'\.', 'g'), + (r'\'', 'g'), + (r'\?[\w\W]*(sevraqvq|punaaryvq|tebhcvq)=([^\&\?#]*)', 'i'), + (r'\s+', 'g'), + (r'^\s*(\S*(\s+\S+)*)\s*$', ''), + (r'(-[a-z])', 'i'), + (r'(^|[^\\])\"\\\/Qngr\((-?[0-9]+)\)\\\/\"', 'g'), + (r'^\s+|\s+$', 'g'), + (r'(?:^|\s+)ba(?:\s+|$)', ''), + (r'[+, ]', ''), + (r'ybnqrq|pbzcyrgr', ''), + (r'\bso_zrah\b', ''), + (r'^(?:(?:[^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?', ''), + (r'uggcf?:\/\/([^\/]+\.)?snprobbx\.pbz\/', ''), + (r'"', 'g'), + (r'^([^?#]+)(?:\?([^#]*))?(#.*)?', ''), + (r'-\D', 'g'), + (r'\bnpgvingr\b', ''), + (r'%2R', 'gi'), + (r'%2S', 'gi'), + (r'^(mu-(PA|GJ)|wn|xb)$', ''), + (r'\s?;\s?', ''), + (r'%\w?$', ''), + (r'TNQP=([^;]*)', 'i'), + (r'[<>]', 'g'), + (r'uers|fep|fryrpgrq', ''), + (r'\s*([+>~\s])\s*([a-zA-Z#.*:\[])', 'g'), + (r'^(\w+|\*)$', ''), + (r'\\\\', 'g'), + (r' ', 'g'), + (r'\/\xc4\/t', ''), + (r'\/\xd6\/t', ''), + (r'\/\xdc\/t', ''), + (r'\/\xdf\/t', ''), + (r'\/\xe4\/t', ''), + (r'\/\xf6\/t', ''), + (r'\/\xfc\/t', ''), + (r'\W', 'g'), + (r'uers|fep|fglyr', ''), + (r'(?:^|\s+)fryrpgrq(?:\s+|$)', ''), + (r'\&', 'g'), + (r'\+', 'g'), + (r'\?', 'g'), + (r'\t', 'g'), + (r'(\$\{nqiHey\})|(\$nqiHey\b)', 'g'), + (r'(\$\{cngu\})|(\$cngu\b)', 'g'), + (r'##yv4##', 'gi'), + (r'##yv16##', 'gi'), + (r'##yv19##', 'gi'), + (r'(?:^|\s+)bss(?:\s+|$)', ''), + (r'^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$', ''), + (r'^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$', ''), + (r'\{0\}', 'g'), + (r'\b[a-z]', 'g'), + (r'^uggc:\/\/', ''), + (r'(?:^|\s+)qvfnoyrq(?:\s+|$)', ''), + (r'zrah_byq', 'g'), + (r'^([#.]?)((?:[\w' + '\u0128-\uffff' + r'*_-]|\\.)*)', ''), + (r'\{1\}', 'g'), + (r'\s+', ''), + (r'(\$\{4\})|(\$4\b)', 'g'), + (r'(\$\{5\})|(\$5\b)', 'g'), + (r'\{2\}', 'g'), + (r'[^+>] [^+>]', ''), + (r'\bucpyv\s*=\s*([^;]*)', 'i'), + (r'\bucuvqr\s*=\s*([^;]*)', 'i'), + (r'\bucfie\s*=\s*([^;]*)', 'i'), + (r'\bhfucjrn\s*=\s*([^;]*)', 'i'), + (r'\bmvc\s*=\s*([^;]*)', 'i'), + (r'^((?:[\w' + '\u0128-\uffff' + r'*_-]|\\.)+)(#)((?:[\w' + + '\u0128-\uffff' + r'*_-]|\\.)+)', ''), + (r'^([>+~])\s*(\w*)', 'i'), + (r'^>\s*((?:[\w' + '\u0128-\uffff' + r'*_-]|\\.)+)', ''), + (r'^[\s[]?shapgvba', ''), + (r'v\/g.tvs#(.*)', 'i'), + (r'eaq_zbqobkva', ''), + (r';\s*', ''), + (r'(\$\{inyhr\})|(\$inyhr\b)', 'g'), + (r'(\$\{abj\})|(\$abj\b)', 'g'), + (r'\s+$', ''), + (r'^\s+', ''), + (r'(\\\"|\x00-|\x1f|\x7f-|\x9f|' + + '\u00ad|\u0600-|\u0604|\u070f|\u17b4|\u17b5|\u200c-|\u200f|\u2028-|\u202f|\u2060-|\u206f|\ufeff|\ufff0-|\uffff' + r')', 'g'), + (r'^(:)([\w-]+)\("?\'?(.*?(\(.*?\))?[^(]*?)"?\'?\)', ''), + (r'^([:.#]*)((?:[\w' + '\u0128-\uffff' + r'*_-]|\\.)+)', ''), + (r'^(\[) *@?([\w-]+) *([!*$^~=]*) *(\'?"?)(.*?)\4 *\]', '')] + + +# The V8 javascript engine only does one replacement unless the regexp has +# the 'g' flag. Python's sub has count = 1 to do 1 replacement and count = 0 +# to replace all matches. We set this up here. + +regexs = [] +subcount = [] + +for s in compiled_regex_strings: + if 'g' in s[1]: + subcount.append(0) + else: + subcount.append(1) + + if 'i' in s[1]: + regexs.append(re.compile(s[0], re.IGNORECASE | re.UNICODE)) + else: + regexs.append(re.compile(s[0], re.UNICODE)) + +# The strings that were in vars in the V8 benchmark + +strings = [ + r'Zbmvyyn/5.0 (Jvaqbjf; H; Jvaqbjf AG 5.1; ra-HF) NccyrJroXvg/528.9 (XUGZY, yvxr Trpxb) Puebzr/2.0.157.0 Fnsnev/528.9', + r'Fubpxjnir Synfu 9.0 e115', + r'{"anzr":"","ahzoreSbezng":{"PheeraplQrpvznyQvtvgf":2,"PheeraplQrpvznyFrcnengbe":".","VfErnqBayl":gehr,"PheeraplTebhcFvmrf":[3],"AhzoreTebhcFvmrf":[3],"CrepragTebhcFvmrf":[3],"PheeraplTebhcFrcnengbe":",","PheeraplFlzoby":"\xa4","AnAFlzoby":"AnA","PheeraplArtngvirCnggrea":0,"AhzoreArtngvirCnggrea":1,"CrepragCbfvgvirCnggrea":0,"CrepragArtngvirCnggrea":0,"ArtngvirVasvavglFlzoby":"-Vasvavgl","ArtngvirFvta":"-","AhzoreQrpvznyQvtvgf":2,"AhzoreQrpvznyFrcnengbe":".","AhzoreTebhcFrcnengbe":",","PheeraplCbfvgvirCnggrea":0,"CbfvgvirVasvavglFlzoby":"Vasvavgl","CbfvgvirFvta":"+","CrepragQrpvznyQvtvgf":2,"CrepragQrpvznyFrcnengbe":".","CrepragTebhcFrcnengbe":",","CrepragFlzoby":"%","CreZvyyrFlzoby":"\u2030","AngvirQvtvgf":["0","1","2","3","4","5","6","7","8","9"],"QvtvgFhofgvghgvba":1},"qngrGvzrSbezng":{"NZQrfvtangbe":"NZ","Pnyraqne":{"ZvaFhccbegrqQngrGvzr":"@-62135568000000@","ZnkFhccbegrqQngrGvzr":"@253402300799999@","NytbevguzGlcr":1,"PnyraqneGlcr":1,"Renf":[1],"GjbQvtvgLrneZnk":2029,"VfErnqBayl":gehr},"QngrFrcnengbe":"/","SvefgQnlBsJrrx":0,"PnyraqneJrrxEhyr":0,"ShyyQngrGvzrCnggrea":"qqqq, qq ZZZZ llll UU:zz:ff","YbatQngrCnggrea":"qqqq, qq ZZZZ llll","YbatGvzrCnggrea":"UU:zz:ff","ZbaguQnlCnggrea":"ZZZZ qq","CZQrfvtangbe":"CZ","ESP1123Cnggrea":"qqq, qq ZZZ llll UU\':\'zz\':\'ff \'TZG\'","FubegQngrCnggrea":"ZZ/qq/llll","FubegGvzrCnggrea":"UU:zz","FbegnoyrQngrGvzrCnggrea":"llll\'-\'ZZ\'-\'qq\'G\'UU\':\'zz\':\'ff","GvzrFrcnengbe":":","HavirefnyFbegnoyrQngrGvzrCnggrea":"llll\'-\'ZZ\'-\'qq UU\':\'zz\':\'ff\'M\'","LrneZbaguCnggrea":"llll ZZZZ","NooerivngrqQnlAnzrf":["Fha","Zba","Ghr","Jrq","Guh","Sev","Fng"],"FubegrfgQnlAnzrf":["Fh","Zb","Gh","Jr","Gu","Se","Fn"],"QnlAnzrf":["Fhaqnl","Zbaqnl","Ghrfqnl","Jrqarfqnl","Guhefqnl","Sevqnl","Fngheqnl"],"NooerivngrqZbaguAnzrf":["Wna","Sro","Zne","Nce","Znl","Wha","Why","Nht","Frc","Bpg","Abi","Qrp",""],"ZbaguAnzrf":["Wnahnel","Sroehnel","Znepu","Ncevy","Znl","Whar","Whyl","Nhthfg","Frcgrzore","Bpgbore","Abirzore","Qrprzore",""],"VfErnqBayl":gehr,"AngvirPnyraqneAnzr":"Tertbevna Pnyraqne","NooerivngrqZbaguTravgvirAnzrf":["Wna","Sro","Zne","Nce","Znl","Wha","Why","Nht","Frc","Bpg","Abi","Qrp",""],"ZbaguTravgvirAnzrf":["Wnahnel","Sroehnel","Znepu","Ncevy","Znl","Whar","Whyl","Nhthfg","Frcgrzore","Bpgbore","Abirzore","Qrprzore",""]}}', + r'{"anzr":"ra-HF","ahzoreSbezng":{"PheeraplQrpvznyQvtvgf":2,"PheeraplQrpvznyFrcnengbe":".","VfErnqBayl":snyfr,"PheeraplTebhcFvmrf":[3],"AhzoreTebhcFvmrf":[3],"CrepragTebhcFvmrf":[3],"PheeraplTebhcFrcnengbe":",","PheeraplFlzoby":"$","AnAFlzoby":"AnA","PheeraplArtngvirCnggrea":0,"AhzoreArtngvirCnggrea":1,"CrepragCbfvgvirCnggrea":0,"CrepragArtngvirCnggrea":0,"ArtngvirVasvavglFlzoby":"-Vasvavgl","ArtngvirFvta":"-","AhzoreQrpvznyQvtvgf":2,"AhzoreQrpvznyFrcnengbe":".","AhzoreTebhcFrcnengbe":",","PheeraplCbfvgvirCnggrea":0,"CbfvgvirVasvavglFlzoby":"Vasvavgl","CbfvgvirFvta":"+","CrepragQrpvznyQvtvgf":2,"CrepragQrpvznyFrcnengbe":".","CrepragTebhcFrcnengbe":",","CrepragFlzoby":"%","CreZvyyrFlzoby":"\u2030","AngvirQvtvgf":["0","1","2","3","4","5","6","7","8","9"],"QvtvgFhofgvghgvba":1},"qngrGvzrSbezng":{"NZQrfvtangbe":"NZ","Pnyraqne":{"ZvaFhccbegrqQngrGvzr":"@-62135568000000@","ZnkFhccbegrqQngrGvzr":"@253402300799999@","NytbevguzGlcr":1,"PnyraqneGlcr":1,"Renf":[1],"GjbQvtvgLrneZnk":2029,"VfErnqBayl":snyfr},"QngrFrcnengbe":"/","SvefgQnlBsJrrx":0,"PnyraqneJrrxEhyr":0,"ShyyQngrGvzrCnggrea":"qqqq, ZZZZ qq, llll u:zz:ff gg","YbatQngrCnggrea":"qqqq, ZZZZ qq, llll","YbatGvzrCnggrea":"u:zz:ff gg","ZbaguQnlCnggrea":"ZZZZ qq","CZQrfvtangbe":"CZ","ESP1123Cnggrea":"qqq, qq ZZZ llll UU\':\'zz\':\'ff \'TZG\'","FubegQngrCnggrea":"Z/q/llll","FubegGvzrCnggrea":"u:zz gg","FbegnoyrQngrGvzrCnggrea":"llll\'-\'ZZ\'-\'qq\'G\'UU\':\'zz\':\'ff","GvzrFrcnengbe":":","HavirefnyFbegnoyrQngrGvzrCnggrea":"llll\'-\'ZZ\'-\'qq UU\':\'zz\':\'ff\'M\'","LrneZbaguCnggrea":"ZZZZ, llll","NooerivngrqQnlAnzrf":["Fha","Zba","Ghr","Jrq","Guh","Sev","Fng"],"FubegrfgQnlAnzrf":["Fh","Zb","Gh","Jr","Gu","Se","Fn"],"QnlAnzrf":["Fhaqnl","Zbaqnl","Ghrfqnl","Jrqarfqnl","Guhefqnl","Sevqnl","Fngheqnl"],"NooerivngrqZbaguAnzrf":["Wna","Sro","Zne","Nce","Znl","Wha","Why","Nht","Frc","Bpg","Abi","Qrp",""],"ZbaguAnzrf":["Wnahnel","Sroehnel","Znepu","Ncevy","Znl","Whar","Whyl","Nhthfg","Frcgrzore","Bpgbore","Abirzore","Qrprzore",""],"VfErnqBayl":snyfr,"AngvirPnyraqneAnzr":"Tertbevna Pnyraqne","NooerivngrqZbaguTravgvirAnzrf":["Wna","Sro","Zne","Nce","Znl","Wha","Why","Nht","Frc","Bpg","Abi","Qrp",""],"ZbaguTravgvirAnzrf":["Wnahnel","Sroehnel","Znepu","Ncevy","Znl","Whar","Whyl","Nhthfg","Frcgrzore","Bpgbore","Abirzore","Qrprzore",""]}}', + r'HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'uggc://jjj.snprobbx.pbz/vaqrk.cuc', + r';;jvaqbj.IjPurpxZbhfrCbfvgvbaNQ_VQ=shapgvba(r){vs(!r)ine r=jvaqbj.rirag;ine c=-1;vs(d1)c=d1.EbyybssCnary;ine bo=IjTrgBow("IjCnayNQ_VQ_"+c);vs(bo&&bo.fglyr.ivfvovyvgl=="ivfvoyr"){ine fns=IjFns?8:0;ine pheK=r.pyvragK+IjBOFpe("U")+fns,pheL=r.pyvragL+IjBOFpe("I")+fns;ine y=IjBOEC(NQ_VQ,bo,"Y"),g=IjBOEC(NQ_VQ,bo,"G");ine e=y+d1.Cnaryf[c].Jvqgu,o=g+d1.Cnaryf[c].Urvtug;vs((pheKe)||(pheLo)){vs(jvaqbj.IjBaEbyybssNQ_VQ)IjBaEbyybssNQ_VQ(c);ryfr IjPybfrNq(NQ_VQ,c,gehr,"");}ryfr erghea;}IjPnapryZbhfrYvfgrareNQ_VQ();};;jvaqbj.IjFrgEbyybssCnaryNQ_VQ=shapgvba(c){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;c=IjTc(NQ_VQ,c);vs(d1&&d1.EbyybssCnary>-1)IjPnapryZbhfrYvfgrareNQ_VQ();vs(d1)d1.EbyybssCnary=c;gel{vs(q.nqqRiragYvfgrare)q.nqqRiragYvfgrare(z,s,snyfr);ryfr vs(q.nggnpuRirag)q.nggnpuRirag("ba"+z,s);}pngpu(r){}};;jvaqbj.IjPnapryZbhfrYvfgrareNQ_VQ=shapgvba(){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;vs(d1)d1.EbyybssCnary=-1;gel{vs(q.erzbirRiragYvfgrare)q.erzbirRiragYvfgrare(z,s,snyfr);ryfr vs(q.qrgnpuRirag)q.qrgnpuRirag("ba"+z,s);}pngpu(r){}};;d1.IjTc=d2(n,c){ine nq=d1;vs(vfAnA(c)){sbe(ine v=0;v0){vs(nq.FzV.yratgu>0)nq.FzV+="/";nq.FzV+=vh[v];nq.FtZ[nq.FtZ.yratgu]=snyfr;}}};;d1.IjYvzvg0=d2(n,f){ine nq=d1,vh=f.fcyvg("/");sbe(ine v=0;v0){vs(nq.OvC.yratgu>0)nq.OvC+="/";nq.OvC+=vh[v];}}};;d1.IjRVST=d2(n,c){jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]=IjTrgBow("IjCnayNQ_VQ_"+c+"_Bow");vs(jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]==ahyy)frgGvzrbhg("IjRVST(NQ_VQ,"+c+")",d1.rvsg);};;d1.IjNavzSHC=d2(n,c){ine nq=d1;vs(c>nq.Cnaryf.yratgu)erghea;ine cna=nq.Cnaryf[c],nn=gehr,on=gehr,yn=gehr,en=gehr,cn=nq.Cnaryf[0],sf=nq.ShF,j=cn.Jvqgu,u=cn.Urvtug;vs(j=="100%"){j=sf;en=snyfr;yn=snyfr;}vs(u=="100%"){u=sf;nn=snyfr;on=snyfr;}vs(cn.YnY=="Y")yn=snyfr;vs(cn.YnY=="E")en=snyfr;vs(cn.GnY=="G")nn=snyfr;vs(cn.GnY=="O")on=snyfr;ine k=0,l=0;fjvgpu(nq.NshP%8){pnfr 0:oernx;pnfr 1:vs(nn)l=-sf;oernx;pnfr 2:k=j-sf;oernx;pnfr 3:vs(en)k=j;oernx;pnfr 4:k=j-sf;l=u-sf;oernx;pnfr 5:k=j-sf;vs(on)l=u;oernx;pnfr 6:l=u-sf;oernx;pnfr 7:vs(yn)k=-sf;l=u-sf;oernx;}vs(nq.NshP++ 0)||(nethzragf.yratgu==3&&bG>0))){pyrneGvzrbhg(cay.UgU);cay.UgU=frgGvzrbhg(cay.UvqrNpgvba,(nethzragf.yratgu==3?bG:cay.UvqrGvzrbhgInyhr));}};;d1.IjErfrgGvzrbhg=d2(n,c,bG){c=IjTc(n,c);IjPnapryGvzrbhg(n,c);riny("IjFgnegGvzrbhg(NQ_VQ,c"+(nethzragf.yratgu==3?",bG":"")+")");};;d1.IjErfrgNyyGvzrbhgf=d2(n){sbe(ine c=0;ce)||(pheLo)){vs(jvaqbj.IjBaEbyybssNQ_VQ)IjBaEbyybssNQ_VQ(c);ryfr IjPybfrNq(NQ_VQ,c,gehr,"");}ryfr erghea;}IjPnapryZbhfrYvfgrareNQ_VQ();};;jvaqbj.IjFrgEbyybssCnaryNQ_VQ=shapgvba(c){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;c=IjTc(NQ_VQ,c);vs(jvaqbj.IjNqNQ_VQ&&jvaqbj.IjNqNQ_VQ.EbyybssCnary>-1)IjPnapryZbhfrYvfgrareNQ_VQ();vs(jvaqbj.IjNqNQ_VQ)jvaqbj.IjNqNQ_VQ.EbyybssCnary=c;gel{vs(q.nqqRiragYvfgrare)q.nqqRiragYvfgrare(z,s,snyfr);ryfr vs(q.nggnpuRirag)q.nggnpuRirag("ba"+z,s);}pngpu(r){}};;jvaqbj.IjPnapryZbhfrYvfgrareNQ_VQ=shapgvba(){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;vs(jvaqbj.IjNqNQ_VQ)jvaqbj.IjNqNQ_VQ.EbyybssCnary=-1;gel{vs(q.erzbirRiragYvfgrare)q.erzbirRiragYvfgrare(z,s,snyfr);ryfr vs(q.qrgnpuRirag)q.qrgnpuRirag("ba"+z,s);}pngpu(r){}};;jvaqbj.IjNqNQ_VQ.IjTc=shapgvba(n,c){ine nq=jvaqbj.IjNqNQ_VQ;vs(vfAnA(c)){sbe(ine v=0;v0){vs(nq.FzV.yratgu>0)nq.FzV+="/";nq.FzV+=vh[v];nq.FtZ[nq.FtZ.yratgu]=snyfr;}}};;jvaqbj.IjNqNQ_VQ.IjYvzvg0=shapgvba(n,f){ine nq=jvaqbj.IjNqNQ_VQ,vh=f.fcyvg("/");sbe(ine v=0;v0){vs(nq.OvC.yratgu>0)nq.OvC+="/";nq.OvC+=vh[v];}}};;jvaqbj.IjNqNQ_VQ.IjRVST=shapgvba(n,c){jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]=IjTrgBow("IjCnayNQ_VQ_"+c+"_Bow");vs(jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]==ahyy)frgGvzrbhg("IjRVST(NQ_VQ,"+c+")",jvaqbj.IjNqNQ_VQ.rvsg);};;jvaqbj.IjNqNQ_VQ.IjNavzSHC=shapgvba(n,c){ine nq=jvaqbj.IjNqNQ_VQ;vs(c>nq.Cnaryf.yratgu)erghea;ine cna=nq.Cnaryf[c],nn=gehr,on=gehr,yn=gehr,en=gehr,cn=nq.Cnaryf[0],sf=nq.ShF,j=cn.Jvqgu,u=cn.Urvtug;vs(j=="100%"){j=sf;en=snyfr;yn=snyfr;}vs(u=="100%"){u=sf;nn=snyfr;on=snyfr;}vs(cn.YnY=="Y")yn=snyfr;vs(cn.YnY=="E")en=snyfr;vs(cn.GnY=="G")nn=snyfr;vs(cn.GnY=="O")on=snyfr;ine k=0,l=0;fjvgpu(nq.NshP%8){pnfr 0:oernx;pnfr 1:vs(nn)l=-sf;oernx;pnfr 2:k=j-sf;oernx;pnfr 3:vs(en)k=j;oernx;pnfr 4:k=j-sf;l=u-sf;oernx;pnfr 5:k=j-sf;vs(on)l=u;oernx;pnfr 6:l=u-sf;oernx;pnfr 7:vs(yn)k=-sf;l=u-sf;oernx;}vs(nq.NshP++ 0)||(nethzragf.yratgu==3&&bG>0))){pyrneGvzrbhg(cay.UgU);cay.UgU=frgGvzrbhg(cay.UvqrNpgvba,(nethzragf.yratgu==3?bG:cay.UvqrGvzrbhgInyhr));}};;jvaqbj.IjNqNQ_VQ.IjErfrgGvzrbhg=shapgvba(n,c,bG){c=IjTc(n,c);IjPnapryGvzrbhg(n,c);riny("IjFgnegGvzrbhg(NQ_VQ,c"+(nethzragf.yratgu==3?",bG":"")+")");};;jvaqbj.IjNqNQ_VQ.IjErfrgNyyGvzrbhgf=shapgvba(n){sbe(ine c=0;ce)||(pheLo)){vs(jvaqbj.IjBaEbyybssNQ_VQ)IjBaEbyybssNQ_VQ(c);ryfr IjPybfrNq(NQ_VQ,c,gehr,"");}ryfr erghea;}IjPnapryZbhfrYvfgrareNQ_VQ();};;jvaqbj.IjFrgEbyybssCnaryNQ_VQ=shapgvba(c){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;c=IjTc(NQ_VQ,c);vs(jvaqbj.IjNqNQ_VQ&&jvaqbj.IjNqNQ_VQ.EbyybssCnary>-1)IjPnapryZbhfrYvfgrareNQ_VQ();vs(jvaqbj.IjNqNQ_VQ)jvaqbj.IjNqNQ_VQ.EbyybssCnary=c;gel{vs(q.nqqRiragYvfgrare)q.nqqRiragYvfgrare(z,s,snyfr);ryfr vs(q.nggnpuRirag)q.nggnpuRirag("ba"+z,s);}pngpu(r){}};;jvaqbj.IjPnapryZbhfrYvfgrareNQ_VQ=shapgvba(){ine z="zbhfrzbir",q=qbphzrag,s=IjPurpxZbhfrCbfvgvbaNQ_VQ;vs(jvaqbj.IjNqNQ_VQ)jvaqbj.IjNqNQ_VQ.EbyybssCnary=-1;gel{vs(q.erzbirRiragYvfgrare)q.erzbirRiragYvfgrare(z,s,snyfr);ryfr vs(q.qrgnpuRirag)q.qrgnpuRirag("ba"+z,s);}pngpu(r){}};;jvaqbj.IjNqNQ_VQ.IjTc=d2(n,c){ine nq=jvaqbj.IjNqNQ_VQ;vs(vfAnA(c)){sbe(ine v=0;v0){vs(nq.FzV.yratgu>0)nq.FzV+="/";nq.FzV+=vh[v];nq.FtZ[nq.FtZ.yratgu]=snyfr;}}};;jvaqbj.IjNqNQ_VQ.IjYvzvg0=d2(n,f){ine nq=jvaqbj.IjNqNQ_VQ,vh=f.fcyvg("/");sbe(ine v=0;v0){vs(nq.OvC.yratgu>0)nq.OvC+="/";nq.OvC+=vh[v];}}};;jvaqbj.IjNqNQ_VQ.IjRVST=d2(n,c){jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]=IjTrgBow("IjCnayNQ_VQ_"+c+"_Bow");vs(jvaqbj["IjCnayNQ_VQ_"+c+"_Bow"]==ahyy)frgGvzrbhg("IjRVST(NQ_VQ,"+c+")",jvaqbj.IjNqNQ_VQ.rvsg);};;jvaqbj.IjNqNQ_VQ.IjNavzSHC=d2(n,c){ine nq=jvaqbj.IjNqNQ_VQ;vs(c>nq.Cnaryf.yratgu)erghea;ine cna=nq.Cnaryf[c],nn=gehr,on=gehr,yn=gehr,en=gehr,cn=nq.Cnaryf[0],sf=nq.ShF,j=cn.Jvqgu,u=cn.Urvtug;vs(j=="100%"){j=sf;en=snyfr;yn=snyfr;}vs(u=="100%"){u=sf;nn=snyfr;on=snyfr;}vs(cn.YnY=="Y")yn=snyfr;vs(cn.YnY=="E")en=snyfr;vs(cn.GnY=="G")nn=snyfr;vs(cn.GnY=="O")on=snyfr;ine k=0,l=0;fjvgpu(nq.NshP%8){pnfr 0:oernx;pnfr 1:vs(nn)l=-sf;oernx;pnfr 2:k=j-sf;oernx;pnfr 3:vs(en)k=j;oernx;pnfr 4:k=j-sf;l=u-sf;oernx;pnfr 5:k=j-sf;vs(on)l=u;oernx;pnfr 6:l=u-sf;oernx;pnfr 7:vs(yn)k=-sf;l=u-sf;oernx;}vs(nq.NshP++ 0)||(nethzragf.yratgu==3&&bG>0))){pyrneGvzrbhg(cay.UgU);cay.UgU=frgGvzrbhg(cay.UvqrNpgvba,(nethzragf.yratgu==3?bG:cay.UvqrGvzrbhgInyhr));}};;jvaqbj.IjNqNQ_VQ.IjErfrgGvzrbhg=d2(n,c,bG){c=IjTc(n,c);IjPnapryGvzrbhg(n,c);riny("IjFgnegGvzrbhg(NQ_VQ,c"+(nethzragf.yratgu==3?",bG":"")+")");};;jvaqbj.IjNqNQ_VQ.IjErfrgNyyGvzrbhgf=d2(n){sbe(ine c=0;c##yv4##Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.##yv19##Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.##yv16##Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl.##OE## ##OE## ##N##Yrnea zber##/N##', + r'Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.##yv19##Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.##yv16##Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl.##OE## ##OE## ##N##Yrnea zber##/N##', + r'Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.##yv19##Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl.##OE## ##OE## ##N##Yrnea zber##/N##', + r'Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl.##OE## ##OE## ##N##Yrnea zber##/N##', + r'Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl. ##N##Yrnea zber##/N##', + r'Cbjreshy Zvpebfbsg grpuabybtl urycf svtug fcnz naq vzcebir frphevgl.Trg zber qbar gunaxf gb terngre rnfr naq fcrrq.Ybgf bs fgbentr (5 TO) - zber pbby fghss ba gur jnl. Yrnea zber##/N##', + r'Bar Jvaqbjf Yvir VQ trgf lbh vagb Ubgznvy, Zrffratre, Kobk YVIR \u2014 naq bgure cynprf lbh frr #~#argjbexybtb#~#', + r'${1}://${2}${3}${4}${5}', + r' O=6gnyg0g4znrrn&o=3&f=gc; Q=_lyu=K3bQZGSxnT4lZzD3OS9GNmV3ZGLkAQxRpTyxNmRlZmRmAmNkAQLRqTImqNZjOUEgpTjQnJ5xMKtgoN--; SCF=qy', + r'FrffvbaQQS2=4ss747o77904333q374or84qrr1s9r0nprp8r5q81534o94n; ZFPhygher=VC=74.125.75.20&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669321699093060&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=; AFP_zp_tfwsbrg-aowb_80=4413268q3660', + r'FrffvbaQQS2=4ss747o77904333q374or84qrr1s9r0nprp8r5q81534o94n; AFP_zp_tfwsbrg-aowb_80=4413268q3660; __hgzm=144631658.1231364074.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.2294274870215848400.1231364074.1231364074.1231364074.1; __hgzo=144631658.0.10.1231364074; __hgzp=144631658; ZFPhygher=VC=74.125.75.20&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669321699093060&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_zlfcnpr-ubzrcntr_wf&qg=1231364057761&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231364057761&punaary=svz_zlfcnpr_ubzrcntr_abgybttrqva%2Psvz_zlfcnpr_aba_HTP%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Ssevraqf.zlfcnpr.pbz%2Svaqrk.psz&nq_glcr=grkg&rvq=6083027&rn=0&sez=0&tn_ivq=1667363813.1231364061&tn_fvq=1231364061&tn_uvq=1917563877&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'ZFPhygher=VC=74.125.75.20&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669321699093060&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.20&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669321699093060&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'uggc://cebsvyr.zlfcnpr.pbz/Zbqhyrf/Nccyvpngvbaf/Cntrf/Pnainf.nfck', + r'FrffvbaQQS2=473qq1rs0n2r70q9qo1pq48n021s9468ron90nps048p4p29; ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669325184628362&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'FrffvbaQQS2=473qq1rs0n2r70q9qo1pq48n021s9468ron90nps048p4p29; __hgzm=144631658.1231364380.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.3931862196947939300.1231364380.1231364380.1231364380.1; __hgzo=144631658.0.10.1231364380; __hgzp=144631658; ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669325184628362&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_vzntrf_wf&qg=1231364373088&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231364373088&punaary=svz_zlfcnpr_hfre-ivrj-pbzzragf%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Spbzzrag.zlfcnpr.pbz%2Svaqrk.psz&nq_glcr=grkg&rvq=6083027&rn=0&sez=0&tn_ivq=1158737789.1231364375&tn_fvq=1231364375&tn_uvq=415520832&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669325184628362&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669325184628362&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'#Zbq-Vasb-Vasb-WninFpevcgUvag', + r',n.svryqOgaPnapry', + r'FrffvbaQQS2=p98s8o9q42nr21or1r61pqorn1n002nsss569635984s6qp7; ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669357391353591&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=; AFP_zp_kkk-gdzogv_80=4413241q3660', + r'FrffvbaQQS2=p98s8o9q42nr21or1r61pqorn1n002nsss569635984s6qp7; AFP_zp_kkk-gdzogv_80=4413241q3660; AFP_zp_kkk-aowb_80=4413235p3660; __hgzm=144631658.1231367708.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.2770915348920628700.1231367708.1231367708.1231367708.1; __hgzo=144631658.0.10.1231367708; __hgzp=144631658; ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669357391353591&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_zlfcnpr-ubzrcntr_wf&qg=1231367691141&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231367691141&punaary=svz_zlfcnpr_ubzrcntr_abgybttrqva%2Psvz_zlfcnpr_aba_HTP%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Sjjj.zlfcnpr.pbz%2S&nq_glcr=grkg&rvq=6083027&rn=0&sez=0&tn_ivq=320757904.1231367694&tn_fvq=1231367694&tn_uvq=1758792003&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'uggc://zfacbegny.112.2b7.arg/o/ff/zfacbegnyubzr/1/U.7-cqi-2/f55332979829981?[NDO]&aqu=1&g=7%2S0%2S2009%2014%3N38%3N42%203%20480&af=zfacbegny&cntrAnzr=HF%20UCZFSGJ&t=uggc%3N%2S%2Sjjj.zfa.pbz%2S&f=1024k768&p=24&x=L&oj=994&ou=634&uc=A&{2}&[NDR]', + r'cnerag puebzr6 fvatyr1 gno fryrpgrq ovaq qbhoyr2 ps', + r'ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669357391353591&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.3&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669357391353591&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'ne;ng;nh;or;oe;pn;pu;py;pa;qr;qx;rf;sv;se;to;ux;vq;vr;va;vg;wc;xe;zk;zl;ay;ab;am;cu;cy;cg;eh;fr;ft;gu;ge;gj;mn;', + r'ZP1=I=3&THVQ=6nnpr9q661804s33nnop45nosqp17q85; zu=ZFSG; PHYGHER=RA-HF; SyvtugTebhcVq=97; SyvtugVq=OnfrCntr; ucfie=Z:5|S:5|G:5|R:5|Q:oyh|J:S; ucpyv=J.U|Y.|F.|E.|H.Y|P.|U.; hfucjrn=jp:HFPN0746; ZHVQ=Q783SN9O14054831N4869R51P0SO8886&GHVQ=1', + r'ZP1=I=3&THVQ=6nnpr9q661804s33nnop45nosqp17q85; zu=ZFSG; PHYGHER=RA-HF; SyvtugTebhcVq=97; SyvtugVq=OnfrCntr; ucfie=Z:5|S:5|G:5|R:5|Q:oyh|J:S; ucpyv=J.U|Y.|F.|E.|H.Y|P.|U.; hfucjrn=jp:HFPN0746; ZHVQ=Q783SN9O14054831N4869R51P0SO8886', + r'ZP1=I=3&THVQ=6nnpr9q661804s33nnop45nosqp17q85; zu=ZFSG; PHYGHER=RA-HF; SyvtugTebhcVq=97; SyvtugVq=OnfrCntr; ucfie=Z:5|S:5|G:5|R:5|Q:oyh|J:S; ucpyv=J.U|Y.|F.|E.|H.Y|P.|U.; hfucjrn=jp:HFPN0746; ZHVQ=Q783SN9O14054831N4869R51P0SO8886; mvc=m:94043|yn:37.4154|yb:-122.0585|p:HF|ue:1', + r'ZP1=I=3&THVQ=6nnpr9q661804s33nnop45nosqp17q85; zu=ZFSG; PHYGHER=RA-HF; SyvtugTebhcVq=97; SyvtugVq=OnfrCntr; ucfie=Z:5|S:5|G:5|R:5|Q:oyh|J:S; ucpyv=J.U|Y.|F.|E.|H.Y|P.|U.; hfucjrn=jp:HFPN0746; ZHVQ=Q783SN9O14054831N4869R51P0SO8886; mvc=m:94043|yn:37.4154|yb:-122.0585|p:HF', + r'uggc://gx2.fgp.f-zfa.pbz/oe/uc/11/ra-hf/pff/v/g.tvs#uggc://gx2.fgo.f-zfa.pbz/v/29/4RQP4969777N048NPS4RRR3PO2S7S.wct', + r'uggc://gx2.fgp.f-zfa.pbz/oe/uc/11/ra-hf/pff/v/g.tvs#uggc://gx2.fgo.f-zfa.pbz/v/OQ/63NP9O94NS5OQP1249Q9S1ROP7NS3.wct', + r'zbmvyyn/5.0 (jvaqbjf; h; jvaqbjf ag 5.1; ra-hf) nccyrjroxvg/528.9 (xugzy, yvxr trpxb) puebzr/2.0.157.0 fnsnev/528.9', + r'1231365729213', + r'74.125.75.3-1057165600.29978900', + r'74.125.75.3-1057165600.29978900.1231365730214', + r'Frnepu%20Zvpebfbsg.pbz', + r'FrffvbaQQS2=8sqq78r9n442851q565599o401385sp3s04r92rnn7o19ssn; ZFPhygher=VC=74.125.75.17&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669340386893867&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'FrffvbaQQS2=8sqq78r9n442851q565599o401385sp3s04r92rnn7o19ssn; __hgzm=144631658.1231365779.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.1877536177953918500.1231365779.1231365779.1231365779.1; __hgzo=144631658.0.10.1231365779; __hgzp=144631658; ZFPhygher=VC=74.125.75.17&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669340386893867&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'I=3%26THVQ=757q3ss871q44o7o805n8113n5p72q52', + r'I=3&THVQ=757q3ss871q44o7o805n8113n5p72q52', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_zlfcnpr-ubzrcntr_wf&qg=1231365765292&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231365765292&punaary=svz_zlfcnpr_ubzrcntr_abgybttrqva%2Psvz_zlfcnpr_aba_HTP%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Sohyyrgvaf.zlfcnpr.pbz%2Svaqrk.psz&nq_glcr=grkg&rvq=6083027&rn=0&sez=0&tn_ivq=1579793869.1231365768&tn_fvq=1231365768&tn_uvq=2056210897&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'frnepu.zvpebfbsg.pbz', + r'frnepu.zvpebfbsg.pbz/', + r'ZFPhygher=VC=74.125.75.17&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669340386893867&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.17&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669340386893867&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'#fubhgobk .pybfr', + r'FrffvbaQQS2=102n9o0o9pq60132qn0337rr867p75953502q2s27s2s5r98; ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669341278771470&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=; AFP_zp_dfctwzssrwh-aowb_80=441326q33660', + r'FrffvbaQQS2=102n9o0o9pq60132qn0337rr867p75953502q2s27s2s5r98; AFP_zp_dfctwzssrwh-aowb_80=441326q33660; __hgzm=144631658.1231365869.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.1670816052019209000.1231365869.1231365869.1231365869.1; __hgzo=144631658.0.10.1231365869; __hgzp=144631658; ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669341278771470&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'FrffvbaQQS2=9995p6rp12rrnr893334ro7nq70o7p64p69rqn844prs1473; ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669350559478880&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=; AFP_zp_dfctwzs-aowb_80=441327q73660', + r'FrffvbaQQS2=9995p6rp12rrnr893334ro7nq70o7p64p69rqn844prs1473; AFP_zp_dfctwzs-aowb_80=441327q73660; __hgzm=144631658.1231367054.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar); __hgzn=144631658.1796080716621419500.1231367054.1231367054.1231367054.1; __hgzo=144631658.0.10.1231367054; __hgzp=144631658; ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669350559478880&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'[glcr=fhozvg]', + r'n.svryqOga,n.svryqOgaPnapry', + r'n.svryqOgaPnapry', + r'oyvpxchaxg', + r'qvi.bow-nppbeqvba qg', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_nccf_wf&qg=1231367052227&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231367052227&punaary=svz_zlfcnpr_nccf-pnainf%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Scebsvyr.zlfcnpr.pbz%2SZbqhyrf%2SNccyvpngvbaf%2SCntrf%2SPnainf.nfck&nq_glcr=grkg&rvq=6083027&rn=0&sez=1&tn_ivq=716357910.1231367056&tn_fvq=1231367056&tn_uvq=1387206491&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'uggc://tbbtyrnqf.t.qbhoyrpyvpx.arg/cntrnq/nqf?pyvrag=pn-svz_zlfcnpr_zlfcnpr-ubzrcntr_wf&qg=1231365851658&uy=ra&nqfnsr=uvtu&br=hgs8&ahz_nqf=4&bhgchg=wf&nqgrfg=bss&pbeeryngbe=1231365851658&punaary=svz_zlfcnpr_ubzrcntr_abgybttrqva%2Psvz_zlfcnpr_aba_HTP%2Psvz_zlfcnpr_havgrq-fgngrf&hey=uggc%3N%2S%2Scebsvyrrqvg.zlfcnpr.pbz%2Svaqrk.psz&nq_glcr=grkg&rvq=6083027&rn=0&sez=0&tn_ivq=1979828129.1231365855&tn_fvq=1231365855&tn_uvq=2085229649&synfu=9.0.115&h_u=768&h_j=1024&h_nu=738&h_nj=1024&h_pq=24&h_gm=-480&h_uvf=2&h_wnin=gehr&h_acyht=7&h_azvzr=22', + r'uggc://zfacbegny.112.2b7.arg/o/ff/zfacbegnyubzr/1/U.7-cqi-2/f55023338617756?[NDO]&aqu=1&g=7%2S0%2S2009%2014%3N12%3N47%203%20480&af=zfacbegny&cntrAnzr=HF%20UCZFSGJ&t=uggc%3N%2S%2Sjjj.zfa.pbz%2S&f=0k0&p=43835816&x=A&oj=994&ou=634&uc=A&{2}&[NDR]', + r'zrgn[anzr=nwnkHey]', + r'anpuevpugra', + r'b oS={\'oT\':1.1};x $8n(B){z(B!=o9)};x $S(B){O(!$8n(B))z A;O(B.4L)z\'T\';b S=7t B;O(S==\'2P\'&&B.p4){23(B.7f){12 1:z\'T\';12 3:z/\S/.2g(B.8M)?\'ox\':\'oh\'}}O(S==\'2P\'||S==\'x\'){23(B.nE){12 2V:z\'1O\';12 7I:z\'5a\';12 18:z\'4B\'}O(7t B.I==\'4F\'){O(B.3u)z\'pG\';O(B.8e)z\'1p\'}}z S};x $2p(){b 4E={};Z(b v=0;v<1p.I;v++){Z(b X 1o 1p[v]){b nc=1p[v][X];b 6E=4E[X];O(6E&&$S(nc)==\'2P\'&&$S(6E)==\'2P\')4E[X]=$2p(6E,nc);17 4E[X]=nc}}z 4E};b $E=7p.E=x(){b 1d=1p;O(!1d[1])1d=[p,1d[0]];Z(b X 1o 1d[1])1d[0][X]=1d[1][X];z 1d[0]};b $4D=7p.pJ=x(){Z(b v=0,y=1p.I;v-1:p.3F(2R)>-1},nX:x(){z p.3y(/([.*+?^${}()|[\]\/\\])/t,\'\\$1\')}});2V.E({5V:x(1O){O(p.I<3)z A;O(p.I==4&&p[3]==0&&!1O)z\'p5\';b 3P=[];Z(b v=0;v<3;v++){b 52=(p[v]-0).4h(16);3P.1x((52.I==1)?\'0\'+52:52)}z 1O?3P:\'#\'+3P.2u(\'\')},5U:x(1O){O(p.I!=3)z A;b 1i=[];Z(b v=0;v<3;v++){1i.1x(5K((p[v].I==1)?p[v]+p[v]:p[v],16))}z 1O?1i:\'1i(\'+1i.2u(\',\')+\')\'}});7F.E({3n:x(P){b J=p;P=$2p({\'L\':J,\'V\':A,\'1p\':1S,\'2x\':A,\'4s\':A,\'6W\':A},P);O($2O(P.1p)&&$S(P.1p)!=\'1O\')P.1p=[P.1p];z x(V){b 1d;O(P.V){V=V||H.V;1d=[(P.V===1r)?V:Y P.V(V)];O(P.1p)1d.E(P.1p)}17 1d=P.1p||1p;b 3C=x(){z J.3H($5S(P', + r'hagreunyghat', + r'ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669341278771470&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&Pbhagel=IIZ%3Q&SbeprqRkcvengvba=633669350559478880&gvzrMbar=-8&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R%3Q', + r'ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669341278771470&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'ZFPhygher=VC=74.125.75.1&VCPhygher=ra-HF&CersreerqPhygher=ra-HF&CersreerqPhygherCraqvat=&Pbhagel=IIZ=&SbeprqRkcvengvba=633669350559478880&gvzrMbar=0&HFEYBP=DKWyLHAiMTH9AwHjWxAcqUx9GJ91oaEunJ4tIzyyqlMQo3IhqUW5D29xMG1IHlMQo3IhqUW5GzSgMG1Iozy0MJDtH3EuqTImWxEgLHAiMTH9BQN3WxkuqTy0qJEyCGZ3YwDkBGVzGT9hM2y0qJEyCF0kZwVhZQH3APMDo3A0LJkQo2EyCGx0ZQDmWyWyM2yiox5uoJH9D0R=', + r'shapgvba (){Cuk.Nccyvpngvba.Frghc.Pber();Cuk.Nccyvpngvba.Frghc.Nwnk();Cuk.Nccyvpngvba.Frghc.Synfu();Cuk.Nccyvpngvba.Frghc.Zbqhyrf()}'] + +# The 12 benchmarking blocks + + +def block0(): + for i in range(6511): + regexs[0].search(r'pyvpx') + + for i in range(1844): + regexs[1].search(r'uggc://jjj.snprobbx.pbz/ybtva.cuc') + + for i in range(739): + regexs[2].sub(r'', 'QBZPbageby_cynprubyqre', subcount[2]) + + for i in range(598): + regexs[1].search(r'uggc://jjj.snprobbx.pbz/') + + for i in range(454): + regexs[1].search(r'uggc://jjj.snprobbx.pbz/fepu.cuc') + + for i in range(352): + re.search( + r'qqqq|qqq|qq|q|ZZZZ|ZZZ|ZZ|Z|llll|ll|l|uu|u|UU|U|zz|z|ff|f|gg|g|sss|ss|s|mmm|mm|m', 'qqqq, ZZZ q, llll') + + for i in range(312): + regexs[3].search(r'vachggrkg QBZPbageby_cynprubyqre') + + for i in range(282): + regexs[4].search(r'/ZlFcnprUbzrcntr/Vaqrk-FvgrUbzr,10000000') + + for i in range(177): + regexs[5].sub(r'', 'vachggrkg', subcount[5]) + + for i in range(170): + regexs[6].sub(r'', '528.9', subcount[6]) + regexs[7].search(r'528') + + for i in range(156): + regexs[8].search(r'VCPhygher=ra-HF') + regexs[8].search(r'CersreerqPhygher=ra-HF') + + for i in range(144): + regexs[0].search(r'xrlcerff') + + for i in range(139): + regexs[6].sub(r'', '521', subcount[6]) + + # This has a different output to the V8 version. + # It could just be a difference in the engines. + regexs[7].search(r'521') + regexs[9].search(r'') + re.search(r'JroXvg\/(\S+)', strings[0]) + + for i in range(137): + regexs[10].sub(r'', 'qvi .so_zrah', subcount[10]) + re.sub(r'\[', '', 'qvi .so_zrah', 0) + regexs[11].sub(r'', 'qvi.so_zrah', subcount[11]) + + for i in range(117): + regexs[2].sub(r'', 'uvqqra_ryrz', subcount[2]) + + for i in range(95): + re.search(r'(?:^|;)\s*sevraqfgre_ynat=([^;]*)', + 'sevraqfgre_naba=nvq%3Qn6ss9p85n868ro9s059pn854735956o3%26ers%3Q%26df%3Q%26vpgl%3QHF') + + for i in range(93): + regexs[12].sub(r'', 'uggc://ubzr.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[13].search(r'uggc://ubzr.zlfcnpr.pbz/vaqrk.psz') + + for i in range(92): + re.sub(r'([a-zA-Z]|\s)+', '', strings[1], 1) + + for i in range(85): + regexs[14].sub(r'', 'svefg', subcount[14]) + regexs[15].sub(r'', 'svefg', subcount[15]) + regexs[12].sub( + r'', 'uggc://cebsvyr.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[14].sub(r'', 'ynfg', subcount[14]) + regexs[15].sub(r'', 'ynfg', subcount[15]) + regexs[16].search(r'qvfcynl') + regexs[13].search(r'uggc://cebsvyr.zlfcnpr.pbz/vaqrk.psz') + + +def block1(): + for i in range(81): + regexs[8].search(r'VC=74.125.75.1') + + for i in range(78): + re.sub(r'(\s)+e', '', '9.0 e115', 1) + re.sub(r'.', '', 'k', 1) + + # This prints a unicode escape where the V8 version prints the + # unicode character. + regexs[17].sub(r'', strings[2], subcount[17]) + + # This prints a unicode escape where the V8 version prints the + # unicode character. + regexs[17].sub(r'', strings[3], subcount[17]) + + regexs[8].search(r'144631658') + regexs[8].search(r'Pbhagel=IIZ%3Q') + regexs[8].search(r'Pbhagel=IIZ=') + regexs[8].search(r'CersreerqPhygherCraqvat=') + regexs[8].search(strings[4]) + regexs[8].search(strings[5]) + regexs[8].search(r'__hgzp=144631658') + regexs[8].search(r'gvzrMbar=-8') + regexs[8].search(r'gvzrMbar=0') + re.search(r'Fnsnev\/(\d+\.\d+)', strings[0]) + regexs[3].search(r'vachggrkg QBZPbageby_cynprubyqre') + regexs[0].search(r'xrlqbja') + regexs[0].search(r'xrlhc') + + for i in range(77): + regexs[12].sub( + r'', 'uggc://zrffntvat.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[13].search(r'uggc://zrffntvat.zlfcnpr.pbz/vaqrk.psz') + + for i in range(73): + regexs[18].sub( + r'', 'FrffvbaFgbentr=%7O%22GnoThvq%22%3N%7O%22thvq%22%3N1231367125017%7Q%7Q', subcount[18]) + + for i in range(72): + regexs[1].search(strings[6]) + + for i in range(71): + regexs[19].search(r'') + + for i in range(70): + regexs[11].sub(r'', '3.5.0.0', subcount[11]) + re.sub(r'd1', '', strings[7], 0) + re.sub(r'NQ_VQ', '', strings[8], 0) + re.sub(r'd2', '', strings[9], 0) + re.sub( + r'_', '', 'NI%3Q1_CI%3Q1_PI%3Q1_EI%3Q1_HI%3Q1_HP%3Q1_IC%3Q0.0.0.0_IH%3Q0', 0) + regexs[20].split( + r'svz_zlfcnpr_ubzrcntr_abgybttrqva,svz_zlfcnpr_aba_HTP,svz_zlfcnpr_havgrq-fgngrf') + regexs[21].search(r'ybnqvat') + + for i in range(68): + regexs[1].search(r'#') + re.search( + r'(?:ZFVR.(\d+\.\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\d+\.\d+))|(?:Bcren.(\d+\.\d+))|(?:NccyrJroXvg.(\d+(?:\.\d+)?))', strings[0]) + re.search(r'(Znp BF K)|(Jvaqbjf;)', strings[0]) + re.search(r'Trpxb\/([0-9]+)', strings[0]) + regexs[21].search(r'ybnqrq') + + for i in range(49): + regexs[16].search(r'pbybe') + + for i in range(44): + regexs[12].sub( + r'', 'uggc://sevraqf.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[13].search(r'uggc://sevraqf.zlfcnpr.pbz/vaqrk.psz') + + +def block2(): + for i in range(40): + regexs[14].sub(r'', 'fryrpgrq', subcount[14]) + regexs[15].sub(r'', 'fryrpgrq', subcount[15]) + + for i in range(39): + re.sub(r'\buvqqra_ryrz\b', '', 'vachggrkg uvqqra_ryrz', 0) + regexs[3].search(r'vachggrkg ') + regexs[3].search(r'vachggrkg') + regexs[22].search(r'HVYvaxOhggba') + regexs[22].search(r'HVYvaxOhggba_E') + regexs[22].search(r'HVYvaxOhggba_EJ') + regexs[22].search(r'zrah_ybtva_pbagnvare') + re.search(r'\buvqqra_ryrz\b', 'vachgcnffjbeq') + + for i in range(37): + regexs[8].search(r'111soqs57qo8o8480qo18sor2011r3n591q7s6s37r120904') + regexs[8].search(r'SbeprqRkcvengvba=633669315660164980') + regexs[8].search( + r'FrffvbaQQS2=111soqs57qo8o8480qo18sor2011r3n591q7s6s37r120904') + + for i in range(35): + regexs[14].sub(r'', 'puvyq p1 svefg', subcount[14]) + regexs[15].sub(r'', 'puvyq p1 svefg', subcount[15]) + regexs[14].sub(r'', 'sylbhg pybfrq', subcount[14]) + regexs[15].sub(r'', 'sylbhg pybfrq', subcount[15]) + + for i in range(34): + regexs[19].search(r'gno2') + regexs[19].search(r'gno3') + regexs[8].search(r'44132r503660') + regexs[8].search(r'SbeprqRkcvengvba=633669316860113296') + regexs[8].search(r'AFP_zp_dfctwzs-aowb_80=44132r503660') + regexs[8].search( + r'FrffvbaQQS2=s6r4579npn4rn2135s904r0s75pp1o5334p6s6pospo12696') + regexs[8].search(r's6r4579npn4rn2135s904r0s75pp1o5334p6s6pospo12696') + + for i in range(32): + re.search(r'puebzr', strings[0], re.IGNORECASE) + + for i in range(31): + regexs[23].sub(r'', 'uggc://jjj.snprobbx.pbz/', subcount[23]) + regexs[8].search(r'SbeprqRkcvengvba=633669358527244818') + regexs[8].search(r'VC=66.249.85.130') + regexs[8].search( + r'FrffvbaQQS2=s15q53p9n372sn76npr13o271n4s3p5r29p235746p908p58') + regexs[8].search(r's15q53p9n372sn76npr13o271n4s3p5r29p235746p908p58') + regexs[24].search(r'uggc://jjj.snprobbx.pbz/') + + for i in range(30): + regexs[6].sub(r'', '419', subcount[6]) + re.search(r'(?:^|\s+)gvzrfgnzc(?:\s+|$)', 'gvzrfgnzc') + regexs[7].search(r'419') + + for i in range(29): + regexs[23].sub(r'', 'uggc://jjj.snprobbx.pbz/ybtva.cuc', subcount[23]) + + for i in range(28): + regexs[25].sub(r'', 'Funer guvf tnqtrg', subcount[25]) + regexs[12].sub(r'', 'Funer guvf tnqtrg', subcount[12]) + regexs[26].search(r'uggc://jjj.tbbtyr.pbz/vt/qverpgbel') + + +def block3(): + for i in range(27): + re.sub(r'[A-Za-z]', '', 'e115', 0) + + for i in range(23): + regexs[27].sub(r'', 'qvfcynl', subcount[27]) + regexs[27].sub(r'', 'cbfvgvba', subcount[27]) + + for i in range(22): + regexs[14].sub(r'', 'unaqyr', subcount[14]) + regexs[15].sub(r'', 'unaqyr', subcount[15]) + regexs[14].sub(r'', 'yvar', subcount[14]) + regexs[15].sub(r'', 'yvar', subcount[15]) + regexs[14].sub(r'', 'cnerag puebzr6 fvatyr1 gno', subcount[14]) + regexs[15].sub(r'', 'cnerag puebzr6 fvatyr1 gno', subcount[15]) + regexs[14].sub(r'', 'fyvqre', subcount[14]) + regexs[15].sub(r'', 'fyvqre', subcount[15]) + regexs[28].search(r'') + + for i in range(21): + regexs[12].sub(r'', 'uggc://jjj.zlfcnpr.pbz/', subcount[12]) + regexs[13].search(r'uggc://jjj.zlfcnpr.pbz/') + + for i in range(20): + regexs[29].sub(r'', 'cntrivrj', subcount[29]) + regexs[30].sub(r'', 'cntrivrj', subcount[30]) + regexs[19].search(r'ynfg') + regexs[19].search(r'ba svefg') + regexs[8].search(r'VC=74.125.75.3') + + for i in range(19): + regexs[31].search(r'ra') + + for i in range(18): + regexs[32].split(strings[10]) + regexs[32].split(strings[11]) + regexs[33].sub(r'', strings[12], subcount[33]) + regexs[8].search(r'144631658.0.10.1231363570') + regexs[8].search( + r'144631658.1231363570.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.3426875219718084000.1231363570.1231363570.1231363570.1') + regexs[8].search(strings[13]) + regexs[8].search(strings[14]) + regexs[8].search( + r'__hgzn=144631658.3426875219718084000.1231363570.1231363570.1231363570.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231363570') + regexs[8].search( + r'__hgzm=144631658.1231363570.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[10]) + regexs[34].search(strings[11]) + + for i in range(17): + re.match(r'zfvr', strings[0], re.IGNORECASE) + re.match(r'bcren', strings[0], re.IGNORECASE) + regexs[32].split(strings[15]) + regexs[32].split(strings[16]) + regexs[14].sub(r'', 'ohggba', subcount[14]) + regexs[15].sub(r'', 'ohggba', subcount[15]) + regexs[14].sub(r'', 'puvyq p1 svefg sylbhg pybfrq', subcount[14]) + regexs[15].sub(r'', 'puvyq p1 svefg sylbhg pybfrq', subcount[15]) + regexs[14].sub(r'', 'pvgvrf', subcount[14]) + regexs[15].sub(r'', 'pvgvrf', subcount[15]) + regexs[14].sub(r'', 'pybfrq', subcount[14]) + regexs[15].sub(r'', 'pybfrq', subcount[15]) + regexs[14].sub(r'', 'qry', subcount[14]) + regexs[15].sub(r'', 'qry', subcount[15]) + regexs[14].sub(r'', 'uqy_zba', subcount[14]) + regexs[15].sub(r'', 'uqy_zba', subcount[15]) + regexs[33].sub(r'', strings[17], subcount[33]) + re.sub(r'%3P', '', strings[18], 0) + re.sub(r'%3R', '', strings[18], 0) + re.sub(r'%3q', '', strings[18], 0) + regexs[35].sub(r'', strings[18], subcount[35]) + regexs[14].sub(r'', 'yvaxyvfg16', subcount[14]) + regexs[15].sub(r'', 'yvaxyvfg16', subcount[15]) + regexs[14].sub(r'', 'zvahf', subcount[14]) + regexs[15].sub(r'', 'zvahf', subcount[15]) + regexs[14].sub(r'', 'bcra', subcount[14]) + regexs[15].sub(r'', 'bcra', subcount[15]) + regexs[14].sub(r'', 'cnerag puebzr5 fvatyr1 ps NU', subcount[14]) + regexs[15].sub(r'', 'cnerag puebzr5 fvatyr1 ps NU', subcount[15]) + regexs[14].sub(r'', 'cynlre', subcount[14]) + regexs[15].sub(r'', 'cynlre', subcount[15]) + regexs[14].sub(r'', 'cyhf', subcount[14]) + regexs[15].sub(r'', 'cyhf', subcount[15]) + regexs[14].sub(r'', 'cb_uqy', subcount[14]) + regexs[15].sub(r'', 'cb_uqy', subcount[15]) + regexs[14].sub(r'', 'hyJVzt', subcount[14]) + regexs[15].sub(r'', 'hyJVzt', subcount[15]) + regexs[8].search(r'144631658.0.10.1231363638') + regexs[8].search( + r'144631658.1231363638.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.965867047679498800.1231363638.1231363638.1231363638.1') + regexs[8].search(r'4413268q3660') + regexs[8].search(r'4ss747o77904333q374or84qrr1s9r0nprp8r5q81534o94n') + regexs[8].search(r'SbeprqRkcvengvba=633669321699093060') + regexs[8].search(r'VC=74.125.75.20') + regexs[8].search(strings[19]) + regexs[8].search(strings[20]) + regexs[8].search(r'AFP_zp_tfwsbrg-aowb_80=4413268q3660') + regexs[8].search( + r'FrffvbaQQS2=4ss747o77904333q374or84qrr1s9r0nprp8r5q81534o94n') + regexs[8].search( + r'__hgzn=144631658.965867047679498800.1231363638.1231363638.1231363638.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231363638') + regexs[8].search( + r'__hgzm=144631658.1231363638.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[15]) + regexs[34].search(strings[16]) + + +def block4(): + for i in range(16): + re.sub(r'\*', '', '', 0) + re.search(r'\bnpgvir\b', 'npgvir') + re.search(r'sversbk', strings[0], re.IGNORECASE) + regexs[36].search(r'glcr') + re.search(r'zfvr', strings[0], re.IGNORECASE) + re.search(r'bcren', strings[0], re.IGNORECASE) + + for i in range(15): + regexs[32].split(strings[21]) + regexs[32].split(strings[22]) + regexs[12].sub( + r'', 'uggc://ohyyrgvaf.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[33].sub(r'', strings[23], subcount[33]) + regexs[37].sub(r'', 'yv', subcount[37]) + regexs[18].sub(r'', 'yv', subcount[18]) + regexs[8].search(r'144631658.0.10.1231367822') + regexs[8].search( + r'144631658.1231367822.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.4127520630321984500.1231367822.1231367822.1231367822.1') + regexs[8].search(strings[24]) + regexs[8].search(strings[25]) + regexs[8].search( + r'__hgzn=144631658.4127520630321984500.1231367822.1231367822.1231367822.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231367822') + regexs[8].search( + r'__hgzm=144631658.1231367822.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[21]) + regexs[34].search(strings[22]) + + # FIXME + # The \{0,65534} should be a * + # There's a current python bug that will stop the regex compilation + # when a * appears there http://bugs.python.org/issue6156. + re.search( + r'\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)["\']?(.*?)["\']?)?\]|:([\w-]+)(?:\(["\']?(.\{0,65534}?)?["\']?\)|$)', strings[26]) + + regexs[13].search(r'uggc://ohyyrgvaf.zlfcnpr.pbz/vaqrk.psz') + regexs[38].search(r'yv') + + for i in range(14): + regexs[18].sub(r'', '', subcount[18]) + re.sub(r'(\s+e|\s+o[0-9]+)', '', '9.0 e115', 1) + re.sub(r'<', '', 'Funer guvf tnqtrg', 0) + re.sub(r'>', '', 'Funer guvf tnqtrg', 0) + regexs[39].sub(r'', 'Funer guvf tnqtrg', subcount[39]) + regexs[12].sub( + r'', 'uggc://cebsvyrrqvg.zlfcnpr.pbz/vaqrk.psz', subcount[12]) + regexs[40].sub(r'', 'grnfre', subcount[40]) + regexs[41].sub(r'', 'grnfre', subcount[41]) + regexs[42].sub(r'', 'grnfre', subcount[42]) + regexs[43].sub(r'', 'grnfre', subcount[43]) + regexs[44].sub(r'', 'grnfre', subcount[44]) + regexs[45].sub(r'', 'grnfre', subcount[45]) + regexs[46].sub(r'', 'grnfre', subcount[46]) + regexs[47].sub(r'', 'grnfre', subcount[47]) + regexs[48].sub(r'', 'grnfre', subcount[48]) + regexs[16].search(r'znetva-gbc') + regexs[16].search(r'cbfvgvba') + regexs[19].search(r'gno1') + regexs[9].search(r'qz') + regexs[9].search(r'qg') + regexs[9].search(r'zbqobk') + regexs[9].search(r'zbqobkva') + regexs[9].search(r'zbqgvgyr') + regexs[13].search(r'uggc://cebsvyrrqvg.zlfcnpr.pbz/vaqrk.psz') + regexs[26].search(r'/vt/znvytnqtrg') + regexs[49].search(r'glcr') + + +def block5(): + for i in range(13): + regexs[14].sub(r'', 'purpx', subcount[14]) + regexs[15].sub(r'', 'purpx', subcount[15]) + regexs[14].sub(r'', 'pvgl', subcount[14]) + regexs[15].sub(r'', 'pvgl', subcount[15]) + regexs[14].sub(r'', 'qrpe fyvqrgrkg', subcount[14]) + regexs[15].sub(r'', 'qrpe fyvqrgrkg', subcount[15]) + regexs[14].sub(r'', 'svefg fryrpgrq', subcount[14]) + regexs[15].sub(r'', 'svefg fryrpgrq', subcount[15]) + regexs[14].sub(r'', 'uqy_rag', subcount[14]) + regexs[15].sub(r'', 'uqy_rag', subcount[15]) + regexs[14].sub(r'', 'vape fyvqrgrkg', subcount[14]) + regexs[15].sub(r'', 'vape fyvqrgrkg', subcount[15]) + regexs[5].sub(r'', 'vachggrkg QBZPbageby_cynprubyqre', subcount[5]) + regexs[14].sub( + r'', 'cnerag puebzr6 fvatyr1 gno fryrpgrq', subcount[14]) + regexs[15].sub( + r'', 'cnerag puebzr6 fvatyr1 gno fryrpgrq', subcount[15]) + regexs[14].sub(r'', 'cb_guz', subcount[14]) + regexs[15].sub(r'', 'cb_guz', subcount[15]) + regexs[14].sub(r'', 'fhozvg', subcount[14]) + regexs[15].sub(r'', 'fhozvg', subcount[15]) + regexs[50].search(r'') + re.search(r'NccyrJroXvg\/([^\s]*)', strings[0]) + re.search(r'XUGZY', strings[0]) + + for i in range(12): + re.sub(r'(\$\{cebg\})|(\$cebg\b)', '', + '${cebg}://${ubfg}${cngu}/${dz}', 0) + regexs[40].sub(r'', '1', subcount[40]) + regexs[10].sub(r'', '1', subcount[10]) + regexs[51].sub(r'', '1', subcount[51]) + regexs[52].sub(r'', '1', subcount[52]) + regexs[53].sub(r'', '1', subcount[53]) + regexs[39].sub(r'', '1', subcount[39]) + regexs[54].sub(r'', '1', subcount[54]) + re.sub(r'^(.*)\..*$', '', '9.0 e115', 1) + re.sub(r'^.*e(.*)$', '', '9.0 e115', 1) + regexs[55].sub(r'', '', subcount[55]) + regexs[55].sub( + r'', '', subcount[55]) + re.sub(r'^.*\s+(\S+\s+\S+$)', '', strings[1], 1) + regexs[30].sub(r'', 'tzk%2Subzrcntr%2Sfgneg%2Sqr%2S', subcount[30]) + regexs[30].sub(r'', 'tzk', subcount[30]) + re.sub(r'(\$\{ubfg\})|(\$ubfg\b)', '', + 'uggc://${ubfg}${cngu}/${dz}', 0) + regexs[56].sub( + r'', 'uggc://nqpyvrag.hvzfrei.arg${cngu}/${dz}', subcount[56]) + re.sub(r'(\$\{dz\})|(\$dz\b)', '', + 'uggc://nqpyvrag.hvzfrei.arg/wf.at/${dz}', 0) + regexs[29].sub(r'', 'frpgvba', subcount[29]) + regexs[30].sub(r'', 'frpgvba', subcount[30]) + regexs[29].sub(r'', 'fvgr', subcount[29]) + regexs[30].sub(r'', 'fvgr', subcount[30]) + regexs[29].sub(r'', 'fcrpvny', subcount[29]) + regexs[30].sub(r'', 'fcrpvny', subcount[30]) + regexs[36].search(r'anzr') + re.search(r'e', '9.0 e115') + + +def block6(): + for i in range(11): + re.sub(r'(?i)##yv0##', '', strings[27], 0) + regexs[57].sub(r'', strings[27], subcount[57]) + regexs[58].sub(r'', strings[28], subcount[58]) + regexs[59].sub(r'', strings[29], subcount[59]) + re.sub(r'(?i)##\/o##', '', strings[30], 0) + re.sub(r'(?i)##\/v##', '', strings[30], 0) + re.sub(r'(?i)##\/h##', '', strings[30], 0) + re.sub(r'(?i)##o##', '', strings[30], 0) + re.sub(r'(?i)##oe##', '', strings[30], 0) + re.sub(r'(?i)##v##', '', strings[30], 0) + re.sub(r'(?i)##h##', '', strings[30], 0) + re.sub(r'(?i)##n##', '', strings[31], 0) + re.sub(r'(?i)##\/n##', '', strings[32], 0) + + # This prints a unicode escape where the V8 version + # prints the unicode character. + re.sub(r'#~#argjbexybtb#~#', '', strings[33], 0) + + re.search(r' Zbovyr\/', strings[0]) + re.search(r'##yv1##', strings[27], re.IGNORECASE) + re.search(r'##yv10##', strings[28], re.IGNORECASE) + re.search(r'##yv11##', strings[28], re.IGNORECASE) + re.search(r'##yv12##', strings[28], re.IGNORECASE) + re.search(r'##yv13##', strings[28], re.IGNORECASE) + re.search(r'##yv14##', strings[28], re.IGNORECASE) + re.search(r'##yv15##', strings[28], re.IGNORECASE) + regexs[58].search(strings[28]) + re.search(r'##yv17##', strings[29], re.IGNORECASE) + re.search(r'##yv18##', strings[29], re.IGNORECASE) + regexs[59].search(strings[29]) + re.search(r'##yv2##', strings[27], re.IGNORECASE) + re.search(r'##yv20##', strings[30], re.IGNORECASE) + re.search(r'##yv21##', strings[30], re.IGNORECASE) + re.search(r'##yv22##', strings[30], re.IGNORECASE) + re.search(r'##yv23##', strings[30], re.IGNORECASE) + re.search(r'##yv3##', strings[27], re.IGNORECASE) + regexs[57].search(strings[27]) + re.search(r'##yv5##', strings[28], re.IGNORECASE) + re.search(r'##yv6##', strings[28], re.IGNORECASE) + re.search(r'##yv7##', strings[28], re.IGNORECASE) + re.search(r'##yv8##', strings[28], re.IGNORECASE) + re.search(r'##yv9##', strings[28], re.IGNORECASE) + regexs[8].search(r'473qq1rs0n2r70q9qo1pq48n021s9468ron90nps048p4p29') + regexs[8].search(r'SbeprqRkcvengvba=633669325184628362') + regexs[8].search( + r'FrffvbaQQS2=473qq1rs0n2r70q9qo1pq48n021s9468ron90nps048p4p29') + re.search(r'AbxvnA[^\/]*', strings[0]) + + for i in range(10): + re.sub(r'(?:^|\s+)bss(?:\s+|$)', '', ' bss', 0) + re.sub(r'(\$\{0\})|(\$0\b)', '', strings[34], 0) + re.sub(r'(\$\{1\})|(\$1\b)', '', strings[34], 0) + re.sub(r'(\$\{pbzcyrgr\})|(\$pbzcyrgr\b)', '', strings[34], 0) + re.sub(r'(\$\{sentzrag\})|(\$sentzrag\b)', '', strings[34], 0) + re.sub(r'(\$\{ubfgcbeg\})|(\$ubfgcbeg\b)', '', strings[34], 0) + regexs[56].sub(r'', strings[34], subcount[56]) + re.sub(r'(\$\{cebgbpby\})|(\$cebgbpby\b)', '', strings[34], 0) + re.sub(r'(\$\{dhrel\})|(\$dhrel\b)', '', strings[34], 0) + regexs[29].sub(r'', 'nqfvmr', subcount[29]) + regexs[30].sub(r'', 'nqfvmr', subcount[30]) + re.sub(r'(\$\{2\})|(\$2\b)', '', 'uggc://${2}${3}${4}${5}', 0) + re.sub(r'(\$\{3\})|(\$3\b)', '', + 'uggc://wf.hv-cbegny.qr${3}${4}${5}', 0) + regexs[40].sub(r'', 'arjf', subcount[40]) + regexs[41].sub(r'', 'arjf', subcount[41]) + regexs[42].sub(r'', 'arjf', subcount[42]) + regexs[43].sub(r'', 'arjf', subcount[43]) + regexs[44].sub(r'', 'arjf', subcount[44]) + regexs[45].sub(r'', 'arjf', subcount[45]) + regexs[46].sub(r'', 'arjf', subcount[46]) + regexs[47].sub(r'', 'arjf', subcount[47]) + regexs[48].sub(r'', 'arjf', subcount[48]) + re.search(r' PC=i=(\d+)&oe=(.)', strings[35]) + regexs[60].search(r' ') + regexs[60].search(r' bss') + regexs[60].search(r'') + regexs[19].search(r' ') + regexs[19].search(r'svefg ba') + regexs[19].search(r'ynfg vtaber') + regexs[19].search(r'ba') + regexs[9].search(r'scnq so ') + regexs[9].search(r'zrqvgobk') + regexs[9].search(r'hsgy') + regexs[9].search(r'lhv-h') + re.search(r'Fnsnev|Xbadhrebe|XUGZY', strings[0], re.IGNORECASE) + regexs[61].search( + r'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/onfr.wf') + regexs[62].search(r'#Ybtva_rznvy') + + +def block7(): + for i in range(9): + regexs[40].sub(r'', '0', subcount[40]) + regexs[10].sub(r'', '0', subcount[10]) + regexs[51].sub(r'', '0', subcount[51]) + regexs[52].sub(r'', '0', subcount[52]) + regexs[53].sub(r'', '0', subcount[53]) + regexs[39].sub(r'', '0', subcount[39]) + regexs[54].sub(r'', '0', subcount[54]) + regexs[40].sub(r'', 'Lrf', subcount[40]) + regexs[10].sub(r'', 'Lrf', subcount[10]) + regexs[51].sub(r'', 'Lrf', subcount[51]) + regexs[52].sub(r'', 'Lrf', subcount[52]) + regexs[53].sub(r'', 'Lrf', subcount[53]) + regexs[39].sub(r'', 'Lrf', subcount[39]) + regexs[54].sub(r'', 'Lrf', subcount[54]) + + for i in range(8): + regexs[63].sub(r'', 'Pybfr {0}', subcount[63]) + regexs[63].sub(r'', 'Bcra {0}', subcount[63]) + regexs[32].split(strings[36]) + regexs[32].split(strings[37]) + regexs[14].sub(r'', 'puvyq p1 svefg gnournqref', subcount[14]) + regexs[15].sub(r'', 'puvyq p1 svefg gnournqref', subcount[15]) + regexs[14].sub(r'', 'uqy_fcb', subcount[14]) + regexs[15].sub(r'', 'uqy_fcb', subcount[15]) + regexs[14].sub(r'', 'uvag', subcount[14]) + regexs[15].sub(r'', 'uvag', subcount[15]) + regexs[33].sub(r'', strings[38], subcount[33]) + regexs[14].sub(r'', 'yvfg', subcount[14]) + regexs[15].sub(r'', 'yvfg', subcount[15]) + regexs[30].sub(r'', 'at_bhgre', subcount[30]) + regexs[14].sub(r'', 'cnerag puebzr5 qbhoyr2 NU', subcount[14]) + regexs[15].sub(r'', 'cnerag puebzr5 qbhoyr2 NU', subcount[15]) + regexs[14].sub( + r'', 'cnerag puebzr5 dhnq5 ps NU osyvax zbarl', subcount[14]) + regexs[15].sub( + r'', 'cnerag puebzr5 dhnq5 ps NU osyvax zbarl', subcount[15]) + regexs[14].sub(r'', 'cnerag puebzr6 fvatyr1', subcount[14]) + regexs[15].sub(r'', 'cnerag puebzr6 fvatyr1', subcount[15]) + regexs[14].sub(r'', 'cb_qrs', subcount[14]) + regexs[15].sub(r'', 'cb_qrs', subcount[15]) + regexs[14].sub(r'', 'gnopbagrag', subcount[14]) + regexs[15].sub(r'', 'gnopbagrag', subcount[15]) + regexs[30].sub(r'', 'iv_svefg_gvzr', subcount[30]) + re.search(r'(^|.)(ronl|qri-ehf3.wbg)(|fgberf|zbgbef|yvirnhpgvbaf|jvxv|rkcerff|punggre).(pbz(|.nh|.pa|.ux|.zl|.ft|.oe|.zk)|pb(.hx|.xe|.am)|pn|qr|se|vg|ay|or|ng|pu|vr|va|rf|cy|cu|fr)$', 'cntrf.ronl.pbz', re.IGNORECASE) + regexs[8].search(r'144631658.0.10.1231364074') + regexs[8].search( + r'144631658.1231364074.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.2294274870215848400.1231364074.1231364074.1231364074.1') + regexs[8].search(r'4413241q3660') + regexs[8].search(r'SbeprqRkcvengvba=633669357391353591') + regexs[8].search(strings[39]) + regexs[8].search(strings[40]) + regexs[8].search(r'AFP_zp_kkk-gdzogv_80=4413241q3660') + regexs[8].search( + r'FrffvbaQQS2=p98s8o9q42nr21or1r61pqorn1n002nsss569635984s6qp7') + regexs[8].search( + r'__hgzn=144631658.2294274870215848400.1231364074.1231364074.1231364074.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231364074') + regexs[8].search( + r'__hgzm=144631658.1231364074.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search(r'p98s8o9q42nr21or1r61pqorn1n002nsss569635984s6qp7') + regexs[34].search(strings[36]) + regexs[34].search(strings[37]) + + +def block8(): + for i in range(7): + re.match(r'\d+', strings[1]) + regexs[64].sub(r'', 'nsgre', subcount[64]) + regexs[64].sub(r'', 'orsber', subcount[64]) + regexs[64].sub(r'', 'obggbz', subcount[64]) + regexs[65].sub(r'', 'ohvygva_jrngure.kzy', subcount[65]) + regexs[37].sub(r'', 'ohggba', subcount[37]) + regexs[18].sub(r'', 'ohggba', subcount[18]) + regexs[65].sub(r'', 'qngrgvzr.kzy', subcount[65]) + regexs[65].sub( + r'', 'uggc://eff.paa.pbz/eff/paa_gbcfgbevrf.eff', subcount[65]) + regexs[37].sub(r'', 'vachg', subcount[37]) + regexs[18].sub(r'', 'vachg', subcount[18]) + regexs[64].sub(r'', 'vafvqr', subcount[64]) + regexs[27].sub(r'', 'cbvagre', subcount[27]) + re.sub(r'[A-Z]', '', 'cbfvgvba', 0) + regexs[27].sub(r'', 'gbc', subcount[27]) + regexs[64].sub(r'', 'gbc', subcount[64]) + regexs[37].sub(r'', 'hy', subcount[37]) + regexs[18].sub(r'', 'hy', subcount[18]) + regexs[37].sub(r'', strings[26], subcount[37]) + regexs[18].sub(r'', strings[26], subcount[18]) + regexs[65].sub(r'', 'lbhghor_vtbbtyr/i2/lbhghor.kzy', subcount[65]) + regexs[27].sub(r'', 'm-vaqrk', subcount[27]) + re.search(r'#([\w-]+)', strings[26]) + regexs[16].search(r'urvtug') + regexs[16].search(r'znetvaGbc') + regexs[16].search(r'jvqgu') + regexs[19].search(r'gno0 svefg ba') + regexs[19].search(r'gno0 ba') + regexs[19].search(r'gno4 ynfg') + regexs[19].search(r'gno4') + regexs[19].search(r'gno5') + regexs[19].search(r'gno6') + regexs[19].search(r'gno7') + regexs[19].search(r'gno8') + re.search(r'NqborNVE\/([^\s]*)', strings[0]) + re.search(r'NccyrJroXvg\/([^ ]*)', strings[0]) + re.search(r'XUGZY', strings[0], re.IGNORECASE) + re.search(r'^(?:obql|ugzy)$', 'YV', re.IGNORECASE) + regexs[38].search(r'ohggba') + regexs[38].search(r'vachg') + regexs[38].search(r'hy') + regexs[38].search(strings[26]) + re.search(r'^(\w+|\*)', strings[26]) + re.search(r'znp|jva|yvahk', 'Jva32', re.IGNORECASE) + re.search(r'eton?\([\d\s,]+\)', 'fgngvp') + + for i in range(6): + re.sub(r'\r', '', '', 0) + regexs[40].sub(r'', '/', subcount[40]) + regexs[10].sub(r'', '/', subcount[10]) + regexs[51].sub(r'', '/', subcount[51]) + regexs[52].sub(r'', '/', subcount[52]) + regexs[53].sub(r'', '/', subcount[53]) + regexs[39].sub(r'', '/', subcount[39]) + regexs[54].sub(r'', '/', subcount[54]) + regexs[63].sub( + r'', 'uggc://zfacbegny.112.2b7.arg/o/ff/zfacbegnyubzr/1/U.7-cqi-2/{0}?[NDO]&{1}&{2}&[NDR]', subcount[63]) + regexs[12].sub(r'', strings[41], subcount[12]) + regexs[23].sub(r'', 'uggc://jjj.snprobbx.pbz/fepu.cuc', subcount[23]) + regexs[40].sub(r'', 'freivpr', subcount[40]) + regexs[41].sub(r'', 'freivpr', subcount[41]) + regexs[42].sub(r'', 'freivpr', subcount[42]) + regexs[43].sub(r'', 'freivpr', subcount[43]) + regexs[44].sub(r'', 'freivpr', subcount[44]) + regexs[45].sub(r'', 'freivpr', subcount[45]) + regexs[46].sub(r'', 'freivpr', subcount[46]) + regexs[47].sub(r'', 'freivpr', subcount[47]) + regexs[48].sub(r'', 'freivpr', subcount[48]) + re.search(r'((ZFVR\s+([6-9]|\d\d)\.))', strings[0]) + regexs[66].search(r'') + regexs[50].search(r'fryrpgrq') + regexs[8].search(r'8sqq78r9n442851q565599o401385sp3s04r92rnn7o19ssn') + regexs[8].search(r'SbeprqRkcvengvba=633669340386893867') + regexs[8].search(r'VC=74.125.75.17') + regexs[8].search( + r'FrffvbaQQS2=8sqq78r9n442851q565599o401385sp3s04r92rnn7o19ssn') + re.search(r'Xbadhrebe|Fnsnev|XUGZY', strings[0]) + regexs[13].search(strings[41]) + regexs[49].search(r'unfsbphf') + + +def block9(): + for i in range(5): + regexs[32].split(strings[42]) + regexs[32].split(strings[43]) + regexs[20].split( + r'svz_zlfcnpr_hfre-ivrj-pbzzragf,svz_zlfcnpr_havgrq-fgngrf') + regexs[33].sub(r'', strings[44], subcount[33]) + regexs[67].sub( + r'', 'zrah_arj zrah_arj_gbttyr zrah_gbttyr', subcount[67]) + regexs[67].sub( + r'', 'zrah_byq zrah_byq_gbttyr zrah_gbttyr', subcount[67]) + regexs[8].search(r'102n9o0o9pq60132qn0337rr867p75953502q2s27s2s5r98') + regexs[8].search(r'144631658.0.10.1231364380') + regexs[8].search( + r'144631658.1231364380.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.3931862196947939300.1231364380.1231364380.1231364380.1') + regexs[8].search(r'441326q33660') + regexs[8].search(r'SbeprqRkcvengvba=633669341278771470') + regexs[8].search(strings[45]) + regexs[8].search(strings[46]) + regexs[8].search(r'AFP_zp_dfctwzssrwh-aowb_80=441326q33660') + regexs[8].search( + r'FrffvbaQQS2=102n9o0o9pq60132qn0337rr867p75953502q2s27s2s5r98') + regexs[8].search( + r'__hgzn=144631658.3931862196947939300.1231364380.1231364380.1231364380.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231364380') + regexs[8].search( + r'__hgzm=144631658.1231364380.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + + for i in range(4): + regexs[14].sub(r'', ' yvfg1', subcount[14]) + regexs[15].sub(r'', ' yvfg1', subcount[15]) + regexs[14].sub(r'', ' yvfg2', subcount[14]) + regexs[15].sub(r'', ' yvfg2', subcount[15]) + regexs[14].sub(r'', ' frneputebhc1', subcount[14]) + regexs[15].sub(r'', ' frneputebhc1', subcount[15]) + regexs[68].sub(r'', strings[47], subcount[68]) + regexs[18].sub(r'', strings[47], subcount[18]) + re.sub(r'&', '', '', 0) + regexs[35].sub(r'', '', subcount[35]) + regexs[63].sub(r'', '(..-{0})(|(d+)|)', subcount[63]) + regexs[18].sub(r'', strings[48], subcount[18]) + regexs[56].sub( + r'', '//vzt.jro.qr/vij/FC/${cngu}/${anzr}/${inyhr}?gf=${abj}', subcount[56]) + re.sub(r'(\$\{anzr\})|(\$anzr\b)', '', + '//vzt.jro.qr/vij/FC/tzk_uc/${anzr}/${inyhr}?gf=${abj}', 0) + regexs[69].sub( + r'', 'Jvaqbjf Yvir Ubgznvy{1}', subcount[69]) + regexs[63].sub( + r'', '{0}{1}', subcount[63]) + regexs[69].sub( + r'', '{1}', subcount[69]) + regexs[63].sub( + r'', '{1}', subcount[63]) + regexs[15].sub(r'', 'Vzntrf', subcount[15]) + regexs[15].sub(r'', 'ZFA', subcount[15]) + regexs[15].sub(r'', 'Zncf', subcount[15]) + regexs[39].sub(r'', 'Zbq-Vasb-Vasb-WninFpevcgUvag', subcount[39]) + regexs[15].sub(r'', 'Arjf', subcount[15]) + regexs[32].split(strings[49]) + regexs[32].split(strings[50]) + regexs[15].sub(r'', 'Ivqrb', subcount[15]) + regexs[15].sub(r'', 'Jro', subcount[15]) + regexs[39].sub(r'', 'n', subcount[39]) + regexs[70].split(r'nwnkFgneg') + regexs[70].split(r'nwnkFgbc') + regexs[14].sub(r'', 'ovaq', subcount[14]) + regexs[15].sub(r'', 'ovaq', subcount[15]) + regexs[63].sub( + r'', 'oevatf lbh zber. Zber fcnpr (5TO), zber frphevgl, fgvyy serr.', subcount[63]) + regexs[14].sub(r'', 'puvyq p1 svefg qrpx', subcount[14]) + regexs[15].sub(r'', 'puvyq p1 svefg qrpx', subcount[15]) + regexs[14].sub(r'', 'puvyq p1 svefg qbhoyr2', subcount[14]) + regexs[15].sub(r'', 'puvyq p1 svefg qbhoyr2', subcount[15]) + regexs[14].sub(r'', 'puvyq p2 ynfg', subcount[14]) + regexs[15].sub(r'', 'puvyq p2 ynfg', subcount[15]) + regexs[14].sub(r'', 'puvyq p2', subcount[14]) + regexs[15].sub(r'', 'puvyq p2', subcount[15]) + regexs[14].sub(r'', 'puvyq p3', subcount[14]) + regexs[15].sub(r'', 'puvyq p3', subcount[15]) + regexs[14].sub(r'', 'puvyq p4 ynfg', subcount[14]) + regexs[15].sub(r'', 'puvyq p4 ynfg', subcount[15]) + regexs[14].sub(r'', 'pbclevtug', subcount[14]) + regexs[15].sub(r'', 'pbclevtug', subcount[15]) + regexs[14].sub(r'', 'qZFAZR_1', subcount[14]) + regexs[15].sub(r'', 'qZFAZR_1', subcount[15]) + regexs[14].sub(r'', 'qbhoyr2 ps', subcount[14]) + regexs[15].sub(r'', 'qbhoyr2 ps', subcount[15]) + regexs[14].sub(r'', 'qbhoyr2', subcount[14]) + regexs[15].sub(r'', 'qbhoyr2', subcount[15]) + regexs[14].sub(r'', 'uqy_arj', subcount[14]) + regexs[15].sub(r'', 'uqy_arj', subcount[15]) + regexs[30].sub(r'', 'uc_fubccvatobk', subcount[30]) + regexs[29].sub(r'', 'ugzy%2Rvq', subcount[29]) + regexs[30].sub(r'', 'ugzy%2Rvq', subcount[30]) + regexs[33].sub(r'', strings[51], subcount[33]) + regexs[71].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/cebgbglcr.wf${4}${5}', subcount[71]) + regexs[72].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/cebgbglcr.wf${5}', subcount[72]) + regexs[73].sub(r'', strings[52], subcount[73]) + regexs[69].sub( + r'', 'uggc://zfacbegny.112.2b7.arg/o/ff/zfacbegnyubzr/1/U.7-cqi-2/f55332979829981?[NDO]&{1}&{2}&[NDR]', subcount[69]) + regexs[14].sub(r'', 'vztZFSG', subcount[14]) + regexs[15].sub(r'', 'vztZFSG', subcount[15]) + regexs[14].sub(r'', 'zfasbbg1 ps', subcount[14]) + regexs[15].sub(r'', 'zfasbbg1 ps', subcount[15]) + regexs[14].sub(r'', strings[53], subcount[14]) + regexs[15].sub(r'', strings[53], subcount[15]) + regexs[14].sub( + r'', 'cnerag puebzr6 fvatyr1 gno fryrpgrq ovaq', subcount[14]) + regexs[15].sub( + r'', 'cnerag puebzr6 fvatyr1 gno fryrpgrq ovaq', subcount[15]) + regexs[14].sub(r'', 'cevznel', subcount[14]) + regexs[15].sub(r'', 'cevznel', subcount[15]) + regexs[30].sub(r'', 'erpgnatyr', subcount[30]) + regexs[14].sub(r'', 'frpbaqnel', subcount[14]) + regexs[15].sub(r'', 'frpbaqnel', subcount[15]) + regexs[70].split(r'haybnq') + regexs[63].sub(r'', '{0}{1}1', subcount[63]) + regexs[69].sub(r'', '|{1}1', subcount[69]) + re.search(r'(..-HF)(\|(\d+)|)', 'xb-xe,ra-va,gu-gu', re.IGNORECASE) + regexs[4].search(r'/ZlFcnprNccf/NccPnainf,45000012') + regexs[8].search(r'144631658.0.10.1231367708') + regexs[8].search( + r'144631658.1231367708.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.2770915348920628700.1231367708.1231367708.1231367708.1') + regexs[8].search(r'4413235p3660') + regexs[8].search(r'441327q73660') + regexs[8].search(r'9995p6rp12rrnr893334ro7nq70o7p64p69rqn844prs1473') + regexs[8].search(r'SbeprqRkcvengvba=633669350559478880') + regexs[8].search(strings[54]) + regexs[8].search(strings[55]) + regexs[8].search(r'AFP_zp_dfctwzs-aowb_80=441327q73660') + regexs[8].search(r'AFP_zp_kkk-aowb_80=4413235p3660') + regexs[8].search( + r'FrffvbaQQS2=9995p6rp12rrnr893334ro7nq70o7p64p69rqn844prs1473') + regexs[8].search( + r'__hgzn=144631658.2770915348920628700.1231367708.1231367708.1231367708.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231367708') + regexs[8].search( + r'__hgzm=144631658.1231367708.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[49]) + regexs[34].search(strings[50]) + re.search(r'ZFVR\s+5[.]01', strings[0]) + re.search(r'HF(?=;)', strings[56], re.IGNORECASE) + regexs[74].search(strings[47]) + regexs[28].search(r'svefg npgvir svefgNpgvir') + regexs[28].search(r'ynfg') + re.search( + r'\bp:(..)', 'm:94043|yn:37.4154|yb:-122.0585|p:HF', re.IGNORECASE) + regexs[75].search(strings[57]) + regexs[75].search(strings[58]) + regexs[76].search(strings[57]) + regexs[76].search(strings[58]) + regexs[77].search(strings[57]) + regexs[77].search(strings[58]) + re.search(r'\bhfucce\s*=\s*([^;]*)', strings[59], re.IGNORECASE) + regexs[78].search(strings[57]) + regexs[78].search(strings[58]) + re.search(r'\bjci\s*=\s*([^;]*)', strings[59], re.IGNORECASE) + regexs[79].search(strings[58]) + regexs[79].search(strings[60]) + regexs[79].search(strings[59]) + re.search( + r'\|p:([a-z]{2})', 'm:94043|yn:37.4154|yb:-122.0585|p:HF|ue:1', re.IGNORECASE) + regexs[80].search(strings[47]) + regexs[61].search(r'cebgbglcr.wf') + regexs[68].search(strings[47]) + regexs[81].search(strings[47]) + regexs[82].search(strings[47]) + re.search(r'^Fubpxjnir Synfu (\d)', strings[1]) + re.search(r'^Fubpxjnir Synfu (\d+)', strings[1]) + regexs[83].search(r'[bowrpg tybony]') + regexs[62].search(strings[47]) + regexs[84].search(strings[61]) + regexs[84].search(strings[62]) + re.search(r'jroxvg', strings[63]) + + +def block10(): + for i in range(3): + regexs[39].sub(r'', '%3Szxg=ra-HF', subcount[39]) + regexs[40].sub(r'', '-8', subcount[40]) + regexs[10].sub(r'', '-8', subcount[10]) + regexs[51].sub(r'', '-8', subcount[51]) + regexs[52].sub(r'', '-8', subcount[52]) + regexs[53].sub(r'', '-8', subcount[53]) + regexs[39].sub(r'', '-8', subcount[39]) + regexs[54].sub(r'', '-8', subcount[54]) + regexs[40].sub(r'', '1.5', subcount[40]) + regexs[10].sub(r'', '1.5', subcount[10]) + regexs[51].sub(r'', '1.5', subcount[51]) + regexs[52].sub(r'', '1.5', subcount[52]) + regexs[53].sub(r'', '1.5', subcount[53]) + regexs[39].sub(r'', '1.5', subcount[39]) + regexs[54].sub(r'', '1.5', subcount[54]) + regexs[40].sub(r'', '1024k768', subcount[40]) + regexs[10].sub(r'', '1024k768', subcount[10]) + regexs[51].sub(r'', '1024k768', subcount[51]) + regexs[52].sub(r'', '1024k768', subcount[52]) + regexs[53].sub(r'', '1024k768', subcount[53]) + regexs[39].sub(r'', '1024k768', subcount[39]) + regexs[54].sub(r'', '1024k768', subcount[54]) + regexs[40].sub(r'', strings[64], subcount[40]) + regexs[10].sub(r'', strings[64], subcount[10]) + regexs[51].sub(r'', strings[64], subcount[51]) + regexs[52].sub(r'', strings[64], subcount[52]) + regexs[53].sub(r'', strings[64], subcount[53]) + regexs[39].sub(r'', strings[64], subcount[39]) + regexs[54].sub(r'', strings[64], subcount[54]) + regexs[40].sub(r'', '14', subcount[40]) + regexs[10].sub(r'', '14', subcount[10]) + regexs[51].sub(r'', '14', subcount[51]) + regexs[52].sub(r'', '14', subcount[52]) + regexs[53].sub(r'', '14', subcount[53]) + regexs[39].sub(r'', '14', subcount[39]) + regexs[54].sub(r'', '14', subcount[54]) + regexs[40].sub(r'', '24', subcount[40]) + regexs[10].sub(r'', '24', subcount[10]) + regexs[51].sub(r'', '24', subcount[51]) + regexs[52].sub(r'', '24', subcount[52]) + regexs[53].sub(r'', '24', subcount[53]) + regexs[39].sub(r'', '24', subcount[39]) + regexs[54].sub(r'', '24', subcount[54]) + regexs[40].sub(r'', strings[65], subcount[40]) + regexs[10].sub(r'', strings[65], subcount[10]) + regexs[51].sub(r'', strings[65], subcount[51]) + regexs[52].sub(r'', strings[65], subcount[52]) + regexs[53].sub(r'', strings[65], subcount[53]) + regexs[39].sub(r'', strings[65], subcount[39]) + regexs[54].sub(r'', strings[65], subcount[54]) + regexs[40].sub(r'', strings[66], subcount[40]) + regexs[10].sub(r'', strings[66], subcount[10]) + regexs[51].sub(r'', strings[66], subcount[51]) + regexs[52].sub(r'', strings[66], subcount[52]) + regexs[53].sub(r'', strings[66], subcount[53]) + regexs[39].sub(r'', strings[66], subcount[39]) + regexs[54].sub(r'', strings[66], subcount[54]) + regexs[40].sub(r'', '9.0', subcount[40]) + regexs[10].sub(r'', '9.0', subcount[10]) + regexs[51].sub(r'', '9.0', subcount[51]) + regexs[52].sub(r'', '9.0', subcount[52]) + regexs[53].sub(r'', '9.0', subcount[53]) + regexs[39].sub(r'', '9.0', subcount[39]) + regexs[54].sub(r'', '9.0', subcount[54]) + regexs[40].sub(r'', '994k634', subcount[40]) + regexs[10].sub(r'', '994k634', subcount[10]) + regexs[51].sub(r'', '994k634', subcount[51]) + regexs[52].sub(r'', '994k634', subcount[52]) + regexs[53].sub(r'', '994k634', subcount[53]) + regexs[39].sub(r'', '994k634', subcount[39]) + regexs[54].sub(r'', '994k634', subcount[54]) + regexs[40].sub(r'', '?zxg=ra-HF', subcount[40]) + regexs[10].sub(r'', '?zxg=ra-HF', subcount[10]) + regexs[51].sub(r'', '?zxg=ra-HF', subcount[51]) + regexs[52].sub(r'', '?zxg=ra-HF', subcount[52]) + regexs[53].sub(r'', '?zxg=ra-HF', subcount[53]) + regexs[54].sub(r'', '?zxg=ra-HF', subcount[54]) + regexs[25].sub(r'', 'PAA.pbz', subcount[25]) + regexs[12].sub(r'', 'PAA.pbz', subcount[12]) + regexs[39].sub(r'', 'PAA.pbz', subcount[39]) + regexs[25].sub(r'', 'Qngr & Gvzr', subcount[25]) + regexs[12].sub(r'', 'Qngr & Gvzr', subcount[12]) + regexs[39].sub(r'', 'Qngr & Gvzr', subcount[39]) + regexs[40].sub(r'', 'Frnepu Zvpebfbsg.pbz', subcount[40]) + regexs[54].sub(r'', 'Frnepu Zvpebfbsg.pbz', subcount[54]) + regexs[10].sub(r'', strings[67], subcount[10]) + regexs[51].sub(r'', strings[67], subcount[51]) + regexs[52].sub(r'', strings[67], subcount[52]) + regexs[53].sub(r'', strings[67], subcount[53]) + regexs[39].sub(r'', strings[67], subcount[39]) + regexs[32].split(strings[68]) + regexs[32].split(strings[69]) + regexs[52].sub(r'', strings[70], subcount[52]) + regexs[53].sub(r'', strings[70], subcount[53]) + regexs[39].sub(r'', strings[70], subcount[39]) + regexs[40].sub(r'', strings[71], subcount[40]) + regexs[10].sub(r'', strings[71], subcount[10]) + regexs[51].sub(r'', strings[71], subcount[51]) + regexs[54].sub(r'', strings[71], subcount[54]) + regexs[25].sub(r'', 'Jrngure', subcount[25]) + regexs[12].sub(r'', 'Jrngure', subcount[12]) + regexs[39].sub(r'', 'Jrngure', subcount[39]) + regexs[25].sub(r'', 'LbhGhor', subcount[25]) + regexs[12].sub(r'', 'LbhGhor', subcount[12]) + regexs[39].sub(r'', 'LbhGhor', subcount[39]) + regexs[33].sub(r'', strings[72], subcount[33]) + re.sub(r'^erzbgr_vsenzr_', '', 'erzbgr_vsenzr_1', 1) + regexs[40].sub(r'', strings[73], subcount[40]) + regexs[10].sub(r'', strings[73], subcount[10]) + regexs[51].sub(r'', strings[73], subcount[51]) + regexs[52].sub(r'', strings[73], subcount[52]) + regexs[53].sub(r'', strings[73], subcount[53]) + regexs[39].sub(r'', strings[73], subcount[39]) + regexs[54].sub(r'', strings[73], subcount[54]) + regexs[40].sub(r'', strings[74], subcount[40]) + regexs[10].sub(r'', strings[74], subcount[10]) + regexs[51].sub(r'', strings[74], subcount[51]) + regexs[52].sub(r'', strings[74], subcount[52]) + regexs[53].sub(r'', strings[74], subcount[53]) + regexs[39].sub(r'', strings[74], subcount[39]) + regexs[54].sub(r'', strings[74], subcount[54]) + re.sub(r'\-', '', 'lhv-h', 0) + regexs[9].search(r'p') + regexs[9].search(r'qz p') + regexs[9].search(r'zbqynory') + regexs[9].search(r'lhv-h svefg') + regexs[8].search(r'144631658.0.10.1231365779') + regexs[8].search( + r'144631658.1231365779.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.1877536177953918500.1231365779.1231365779.1231365779.1') + regexs[8].search(strings[75]) + regexs[8].search(strings[76]) + regexs[8].search( + r'__hgzn=144631658.1877536177953918500.1231365779.1231365779.1231365779.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231365779') + regexs[8].search( + r'__hgzm=144631658.1231365779.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[68]) + regexs[34].search(strings[69]) + re.search(r'^$', '') + regexs[31].search(r'qr') + re.search(r'^znk\d+$', '') + re.search(r'^zva\d+$', '') + re.search(r'^erfgber$', '') + regexs[85].search(r'zbqobkva zbqobk_abcnqqvat ') + regexs[85].search(r'zbqgvgyr') + regexs[85].search(r'eaq_zbqobkva ') + regexs[85].search(r'eaq_zbqgvgyr ') + re.search(r'frpgvba\d+_pbagragf', 'obggbz_ani') + + +def block11(): + for i in range(2): + regexs[18].sub(r'', ' .pybfr', subcount[18]) + regexs[18].sub(r'', ' n.svryqOgaPnapry', subcount[18]) + regexs[18].sub(r'', ' qg', subcount[18]) + regexs[68].sub(r'', strings[77], subcount[68]) + regexs[18].sub(r'', strings[77], subcount[18]) + regexs[39].sub(r'', '', subcount[39]) + re.sub(r'^', '', '', 1) + regexs[86].split(r'') + regexs[39].sub(r'', '*', subcount[39]) + regexs[68].sub(r'', '*', subcount[68]) + regexs[18].sub(r'', '*', subcount[18]) + regexs[68].sub(r'', '.pybfr', subcount[68]) + regexs[18].sub(r'', '.pybfr', subcount[18]) + regexs[87].sub( + r'', '//vzt.jro.qr/vij/FC/tzk_uc/fperra/${inyhr}?gf=${abj}', subcount[87]) + regexs[88].sub( + r'', '//vzt.jro.qr/vij/FC/tzk_uc/fperra/1024?gf=${abj}', subcount[88]) + regexs[87].sub( + r'', '//vzt.jro.qr/vij/FC/tzk_uc/jvafvmr/${inyhr}?gf=${abj}', subcount[87]) + regexs[88].sub( + r'', '//vzt.jro.qr/vij/FC/tzk_uc/jvafvmr/992/608?gf=${abj}', subcount[88]) + regexs[30].sub(r'', '300k120', subcount[30]) + regexs[30].sub(r'', '300k250', subcount[30]) + regexs[30].sub(r'', '310k120', subcount[30]) + regexs[30].sub(r'', '310k170', subcount[30]) + regexs[30].sub(r'', '310k250', subcount[30]) + re.sub(r'^.*\.(.*)\s.*$', '', '9.0 e115', 1) + regexs[2].sub(r'', 'Nppbeqvba', subcount[2]) + regexs[89].sub(r'', 'Nxghryy\x0a', subcount[89]) + regexs[90].sub(r'', 'Nxghryy\x0a', subcount[90]) + regexs[2].sub(r'', 'Nccyvpngvba', subcount[2]) + regexs[89].sub(r'', 'Oyvpxchaxg\x0a', subcount[89]) + regexs[90].sub(r'', 'Oyvpxchaxg\x0a', subcount[90]) + regexs[89].sub(r'', 'Svanamra\x0a', subcount[89]) + regexs[90].sub(r'', 'Svanamra\x0a', subcount[90]) + regexs[89].sub(r'', 'Tnzrf\x0a', subcount[89]) + regexs[90].sub(r'', 'Tnzrf\x0a', subcount[90]) + regexs[89].sub(r'', 'Ubebfxbc\x0a', subcount[89]) + regexs[90].sub(r'', 'Ubebfxbc\x0a', subcount[90]) + regexs[89].sub(r'', 'Xvab\x0a', subcount[89]) + regexs[90].sub(r'', 'Xvab\x0a', subcount[90]) + regexs[2].sub(r'', 'Zbqhyrf', subcount[2]) + regexs[89].sub(r'', 'Zhfvx\x0a', subcount[89]) + regexs[90].sub(r'', 'Zhfvx\x0a', subcount[90]) + regexs[89].sub(r'', 'Anpuevpugra\x0a', subcount[89]) + regexs[90].sub(r'', 'Anpuevpugra\x0a', subcount[90]) + regexs[2].sub(r'', 'Cuk', subcount[2]) + regexs[70].split(r'ErdhrfgSvavfu') + regexs[70].split(r'ErdhrfgSvavfu.NWNK.Cuk') + regexs[89].sub(r'', 'Ebhgr\x0a', subcount[89]) + regexs[90].sub(r'', 'Ebhgr\x0a', subcount[90]) + regexs[32].split(strings[78]) + regexs[32].split(strings[79]) + regexs[32].split(strings[80]) + regexs[32].split(strings[81]) + regexs[89].sub(r'', 'Fcbeg\x0a', subcount[89]) + regexs[90].sub(r'', 'Fcbeg\x0a', subcount[90]) + regexs[89].sub(r'', 'GI-Fcbg\x0a', subcount[89]) + regexs[90].sub(r'', 'GI-Fcbg\x0a', subcount[90]) + regexs[89].sub(r'', 'Gbhe\x0a', subcount[89]) + regexs[90].sub(r'', 'Gbhe\x0a', subcount[90]) + regexs[89].sub(r'', 'Hagreunyghat\x0a', subcount[89]) + regexs[90].sub(r'', 'Hagreunyghat\x0a', subcount[90]) + regexs[89].sub(r'', 'Ivqrb\x0a', subcount[89]) + regexs[90].sub(r'', 'Ivqrb\x0a', subcount[90]) + regexs[89].sub(r'', 'Jrggre\x0a', subcount[89]) + regexs[90].sub(r'', 'Jrggre\x0a', subcount[90]) + regexs[68].sub(r'', strings[82], subcount[68]) + regexs[18].sub(r'', strings[82], subcount[18]) + regexs[68].sub(r'', strings[83], subcount[68]) + regexs[18].sub(r'', strings[83], subcount[18]) + regexs[68].sub(r'', strings[84], subcount[68]) + regexs[18].sub(r'', strings[84], subcount[18]) + regexs[30].sub(r'', 'nqiFreivprObk', subcount[30]) + regexs[30].sub(r'', 'nqiFubccvatObk', subcount[30]) + regexs[39].sub(r'', 'nwnk', subcount[39]) + regexs[40].sub(r'', 'nxghryy', subcount[40]) + regexs[41].sub(r'', 'nxghryy', subcount[41]) + regexs[42].sub(r'', 'nxghryy', subcount[42]) + regexs[43].sub(r'', 'nxghryy', subcount[43]) + regexs[44].sub(r'', 'nxghryy', subcount[44]) + regexs[45].sub(r'', 'nxghryy', subcount[45]) + regexs[46].sub(r'', 'nxghryy', subcount[46]) + regexs[47].sub(r'', 'nxghryy', subcount[47]) + regexs[48].sub(r'', 'nxghryy', subcount[48]) + regexs[40].sub(r'', strings[85], subcount[40]) + regexs[41].sub(r'', strings[85], subcount[41]) + regexs[42].sub(r'', strings[85], subcount[42]) + regexs[43].sub(r'', strings[85], subcount[43]) + regexs[44].sub(r'', strings[85], subcount[44]) + regexs[45].sub(r'', strings[85], subcount[45]) + regexs[46].sub(r'', strings[85], subcount[46]) + regexs[47].sub(r'', strings[85], subcount[47]) + regexs[48].sub(r'', strings[85], subcount[48]) + regexs[29].sub(r'', 'pngrtbel', subcount[29]) + regexs[30].sub(r'', 'pngrtbel', subcount[30]) + regexs[39].sub(r'', 'pybfr', subcount[39]) + regexs[39].sub(r'', 'qvi', subcount[39]) + regexs[68].sub(r'', strings[86], subcount[68]) + regexs[18].sub(r'', strings[86], subcount[18]) + regexs[39].sub(r'', 'qg', subcount[39]) + regexs[68].sub(r'', 'qg', subcount[68]) + regexs[18].sub(r'', 'qg', subcount[18]) + regexs[39].sub(r'', 'rzorq', subcount[39]) + regexs[68].sub(r'', 'rzorq', subcount[68]) + regexs[18].sub(r'', 'rzorq', subcount[18]) + regexs[39].sub(r'', 'svryqOga', subcount[39]) + regexs[39].sub(r'', 'svryqOgaPnapry', subcount[39]) + regexs[20].split(r'svz_zlfcnpr_nccf-pnainf,svz_zlfcnpr_havgrq-fgngrf') + regexs[40].sub(r'', 'svanamra', subcount[40]) + regexs[41].sub(r'', 'svanamra', subcount[41]) + regexs[42].sub(r'', 'svanamra', subcount[42]) + regexs[43].sub(r'', 'svanamra', subcount[43]) + regexs[44].sub(r'', 'svanamra', subcount[44]) + regexs[45].sub(r'', 'svanamra', subcount[45]) + regexs[46].sub(r'', 'svanamra', subcount[46]) + regexs[47].sub(r'', 'svanamra', subcount[47]) + regexs[48].sub(r'', 'svanamra', subcount[48]) + regexs[70].split(r'sbphf') + regexs[70].split(r'sbphf.gno sbphfva.gno') + regexs[70].split(r'sbphfva') + regexs[39].sub(r'', 'sbez', subcount[39]) + regexs[68].sub(r'', 'sbez.nwnk', subcount[68]) + regexs[18].sub(r'', 'sbez.nwnk', subcount[18]) + regexs[40].sub(r'', 'tnzrf', subcount[40]) + regexs[41].sub(r'', 'tnzrf', subcount[41]) + regexs[42].sub(r'', 'tnzrf', subcount[42]) + regexs[43].sub(r'', 'tnzrf', subcount[43]) + regexs[44].sub(r'', 'tnzrf', subcount[44]) + regexs[45].sub(r'', 'tnzrf', subcount[45]) + regexs[46].sub(r'', 'tnzrf', subcount[46]) + regexs[47].sub(r'', 'tnzrf', subcount[47]) + regexs[48].sub(r'', 'tnzrf', subcount[48]) + regexs[30].sub(r'', 'ubzrcntr', subcount[30]) + regexs[40].sub(r'', 'ubebfxbc', subcount[40]) + regexs[41].sub(r'', 'ubebfxbc', subcount[41]) + regexs[42].sub(r'', 'ubebfxbc', subcount[42]) + regexs[43].sub(r'', 'ubebfxbc', subcount[43]) + regexs[44].sub(r'', 'ubebfxbc', subcount[44]) + regexs[45].sub(r'', 'ubebfxbc', subcount[45]) + regexs[46].sub(r'', 'ubebfxbc', subcount[46]) + regexs[47].sub(r'', 'ubebfxbc', subcount[47]) + regexs[48].sub(r'', 'ubebfxbc', subcount[48]) + regexs[30].sub(r'', 'uc_cebzbobk_ugzy%2Puc_cebzbobk_vzt', subcount[30]) + regexs[30].sub(r'', 'uc_erpgnatyr', subcount[30]) + regexs[33].sub(r'', strings[87], subcount[33]) + regexs[33].sub(r'', strings[88], subcount[33]) + regexs[71].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/onfr.wf${4}${5}', subcount[71]) + regexs[72].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/onfr.wf${5}', subcount[72]) + regexs[71].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/qlaYvo.wf${4}${5}', subcount[71]) + regexs[72].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/qlaYvo.wf${5}', subcount[72]) + regexs[71].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/rssrpgYvo.wf${4}${5}', subcount[71]) + regexs[72].sub( + r'', 'uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/rssrpgYvo.wf${5}', subcount[72]) + regexs[73].sub(r'', strings[89], subcount[73]) + regexs[69].sub( + r'', 'uggc://zfacbegny.112.2b7.arg/o/ff/zfacbegnyubzr/1/U.7-cqi-2/f55023338617756?[NDO]&{1}&{2}&[NDR]', subcount[69]) + regexs[23].sub(r'', strings[6], subcount[23]) + regexs[40].sub(r'', 'xvab', subcount[40]) + regexs[41].sub(r'', 'xvab', subcount[41]) + regexs[42].sub(r'', 'xvab', subcount[42]) + regexs[43].sub(r'', 'xvab', subcount[43]) + regexs[44].sub(r'', 'xvab', subcount[44]) + regexs[45].sub(r'', 'xvab', subcount[45]) + regexs[46].sub(r'', 'xvab', subcount[46]) + regexs[47].sub(r'', 'xvab', subcount[47]) + regexs[48].sub(r'', 'xvab', subcount[48]) + regexs[70].split(r'ybnq') + regexs[18].sub( + r'', 'zrqvnzbqgno lhv-anifrg lhv-anifrg-gbc', subcount[18]) + regexs[39].sub(r'', 'zrgn', subcount[39]) + regexs[68].sub(r'', strings[90], subcount[68]) + regexs[18].sub(r'', strings[90], subcount[18]) + regexs[70].split(r'zbhfrzbir') + regexs[70].split(r'zbhfrzbir.gno') + re.sub(r'^.*jroxvg\/(\d+(\.\d+)?).*$', '', strings[63], 1) + regexs[40].sub(r'', 'zhfvx', subcount[40]) + regexs[41].sub(r'', 'zhfvx', subcount[41]) + regexs[42].sub(r'', 'zhfvx', subcount[42]) + regexs[43].sub(r'', 'zhfvx', subcount[43]) + regexs[44].sub(r'', 'zhfvx', subcount[44]) + regexs[45].sub(r'', 'zhfvx', subcount[45]) + regexs[46].sub(r'', 'zhfvx', subcount[46]) + regexs[47].sub(r'', 'zhfvx', subcount[47]) + regexs[48].sub(r'', 'zhfvx', subcount[48]) + regexs[52].sub(r'', 'zlfcnpr_nccf_pnainf', subcount[52]) + regexs[40].sub(r'', strings[91], subcount[40]) + regexs[41].sub(r'', strings[91], subcount[41]) + regexs[42].sub(r'', strings[91], subcount[42]) + regexs[43].sub(r'', strings[91], subcount[43]) + regexs[44].sub(r'', strings[91], subcount[44]) + regexs[45].sub(r'', strings[91], subcount[45]) + regexs[46].sub(r'', strings[91], subcount[46]) + regexs[47].sub(r'', strings[91], subcount[47]) + regexs[48].sub(r'', strings[91], subcount[48]) + regexs[39].sub(r'', 'anzr', subcount[39]) + + # This prints something different to the V8 version + # The V8 version is escaping different things in the string that + # has the substitutions performed on it. + # + # V8 treats /\S/ like / + escaped S + / + # Python treats it like / + \ + S + / + re.sub(r'\b\w+\b', '', strings[92], 0) + + regexs[39].sub(r'', 'bow-nppbeqvba', subcount[39]) + regexs[39].sub(r'', 'bowrpg', subcount[39]) + regexs[68].sub(r'', 'bowrpg', subcount[68]) + regexs[18].sub(r'', 'bowrpg', subcount[18]) + regexs[29].sub(r'', 'cnenzf%2Rfglyrf', subcount[29]) + regexs[30].sub(r'', 'cnenzf%2Rfglyrf', subcount[30]) + regexs[30].sub(r'', 'cbchc', subcount[30]) + regexs[40].sub(r'', 'ebhgr', subcount[40]) + regexs[41].sub(r'', 'ebhgr', subcount[41]) + regexs[42].sub(r'', 'ebhgr', subcount[42]) + regexs[43].sub(r'', 'ebhgr', subcount[43]) + regexs[44].sub(r'', 'ebhgr', subcount[44]) + regexs[45].sub(r'', 'ebhgr', subcount[45]) + regexs[46].sub(r'', 'ebhgr', subcount[46]) + regexs[47].sub(r'', 'ebhgr', subcount[47]) + regexs[48].sub(r'', 'ebhgr', subcount[48]) + regexs[30].sub(r'', 'freivprobk_uc', subcount[30]) + regexs[30].sub(r'', 'fubccvatobk_uc', subcount[30]) + regexs[39].sub(r'', 'fubhgobk', subcount[39]) + regexs[40].sub(r'', 'fcbeg', subcount[40]) + regexs[41].sub(r'', 'fcbeg', subcount[41]) + regexs[42].sub(r'', 'fcbeg', subcount[42]) + regexs[43].sub(r'', 'fcbeg', subcount[43]) + regexs[44].sub(r'', 'fcbeg', subcount[44]) + regexs[45].sub(r'', 'fcbeg', subcount[45]) + regexs[46].sub(r'', 'fcbeg', subcount[46]) + regexs[47].sub(r'', 'fcbeg', subcount[47]) + regexs[48].sub(r'', 'fcbeg', subcount[48]) + regexs[40].sub(r'', 'gbhe', subcount[40]) + regexs[41].sub(r'', 'gbhe', subcount[41]) + regexs[42].sub(r'', 'gbhe', subcount[42]) + regexs[43].sub(r'', 'gbhe', subcount[43]) + regexs[44].sub(r'', 'gbhe', subcount[44]) + regexs[45].sub(r'', 'gbhe', subcount[45]) + regexs[46].sub(r'', 'gbhe', subcount[46]) + regexs[47].sub(r'', 'gbhe', subcount[47]) + regexs[48].sub(r'', 'gbhe', subcount[48]) + regexs[40].sub(r'', 'gi-fcbg', subcount[40]) + regexs[41].sub(r'', 'gi-fcbg', subcount[41]) + regexs[42].sub(r'', 'gi-fcbg', subcount[42]) + regexs[43].sub(r'', 'gi-fcbg', subcount[43]) + regexs[44].sub(r'', 'gi-fcbg', subcount[44]) + regexs[45].sub(r'', 'gi-fcbg', subcount[45]) + regexs[46].sub(r'', 'gi-fcbg', subcount[46]) + regexs[47].sub(r'', 'gi-fcbg', subcount[47]) + regexs[48].sub(r'', 'gi-fcbg', subcount[48]) + regexs[39].sub(r'', 'glcr', subcount[39]) + re.sub(r'\/', '', 'haqrsvarq', 0) + regexs[40].sub(r'', strings[93], subcount[40]) + regexs[41].sub(r'', strings[93], subcount[41]) + regexs[42].sub(r'', strings[93], subcount[42]) + regexs[43].sub(r'', strings[93], subcount[43]) + regexs[44].sub(r'', strings[93], subcount[44]) + regexs[45].sub(r'', strings[93], subcount[45]) + regexs[46].sub(r'', strings[93], subcount[46]) + regexs[47].sub(r'', strings[93], subcount[47]) + regexs[48].sub(r'', strings[93], subcount[48]) + regexs[40].sub(r'', 'ivqrb', subcount[40]) + regexs[41].sub(r'', 'ivqrb', subcount[41]) + regexs[42].sub(r'', 'ivqrb', subcount[42]) + regexs[43].sub(r'', 'ivqrb', subcount[43]) + regexs[44].sub(r'', 'ivqrb', subcount[44]) + regexs[45].sub(r'', 'ivqrb', subcount[45]) + regexs[46].sub(r'', 'ivqrb', subcount[46]) + regexs[47].sub(r'', 'ivqrb', subcount[47]) + regexs[48].sub(r'', 'ivqrb', subcount[48]) + regexs[86].split(r'ivfvgf=1') + regexs[40].sub(r'', 'jrggre', subcount[40]) + regexs[41].sub(r'', 'jrggre', subcount[41]) + regexs[42].sub(r'', 'jrggre', subcount[42]) + regexs[43].sub(r'', 'jrggre', subcount[43]) + regexs[44].sub(r'', 'jrggre', subcount[44]) + regexs[45].sub(r'', 'jrggre', subcount[45]) + regexs[46].sub(r'', 'jrggre', subcount[46]) + regexs[47].sub(r'', 'jrggre', subcount[47]) + regexs[48].sub(r'', 'jrggre', subcount[48]) + re.search(r'#[a-z0-9]+$', + 'uggc://jjj.fpuhryreim.arg/Qrsnhyg', re.IGNORECASE) + regexs[66].search(r'fryrpgrq') + re.search(r'(?:^|\s+)lhv-ani(?:\s+|$)', 'sff lhv-ani') + re.search(r'(?:^|\s+)lhv-anifrg(?:\s+|$)', 'zrqvnzbqgno lhv-anifrg') + re.search(r'(?:^|\s+)lhv-anifrg-gbc(?:\s+|$)', + 'zrqvnzbqgno lhv-anifrg') + regexs[91].search(r'GnoThvq') + regexs[91].search(r'thvq') + re.search(r'(pbzcngvoyr|jroxvg)', strings[63]) + re.search(r'.+(?:ei|vg|en|vr)[\/: ]([\d.]+)', strings[63]) + regexs[8].search(r'144631658.0.10.1231365869') + regexs[8].search(r'144631658.0.10.1231367054') + regexs[8].search( + r'144631658.1231365869.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.1231367054.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'144631658.1670816052019209000.1231365869.1231365869.1231365869.1') + regexs[8].search( + r'144631658.1796080716621419500.1231367054.1231367054.1231367054.1') + regexs[8].search(strings[94]) + regexs[8].search(strings[95]) + regexs[8].search(strings[96]) + regexs[8].search(strings[97]) + regexs[8].search( + r'__hgzn=144631658.1670816052019209000.1231365869.1231365869.1231365869.1') + regexs[8].search( + r'__hgzn=144631658.1796080716621419500.1231367054.1231367054.1231367054.1') + regexs[8].search(r'__hgzo=144631658.0.10.1231365869') + regexs[8].search(r'__hgzo=144631658.0.10.1231367054') + regexs[8].search( + r'__hgzm=144631658.1231365869.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[8].search( + r'__hgzm=144631658.1231367054.1.1.hgzpfe=(qverpg)|hgzppa=(qverpg)|hgzpzq=(abar)') + regexs[34].search(strings[78]) + regexs[34].search(strings[79]) + regexs[34].search(strings[81]) + regexs[74].search(strings[77]) + regexs[74].search(r'*') + regexs[74].search(strings[82]) + regexs[74].search(strings[83]) + regexs[74].search(strings[86]) + regexs[74].search(r'rzorq') + regexs[74].search(r'sbez.nwnk') + regexs[74].search(strings[90]) + regexs[74].search(r'bowrpg') + re.search(r'\/onfr.wf(\?.+)?$', + '/uggc://wf.hv-cbegny.qr/tzk/ubzr/wf/20080602/onfr.wf') + regexs[28].search(r'uvag ynfgUvag ynfg') + regexs[75].search(r'') + regexs[76].search(r'') + regexs[77].search(r'') + regexs[78].search(r'') + regexs[80].search(strings[77]) + regexs[80].search(r'*') + regexs[80].search(r'.pybfr') + regexs[80].search(strings[82]) + regexs[80].search(strings[83]) + regexs[80].search(strings[84]) + regexs[80].search(strings[86]) + regexs[80].search(r'qg') + regexs[80].search(r'rzorq') + regexs[80].search(r'sbez.nwnk') + regexs[80].search(strings[90]) + regexs[80].search(r'bowrpg') + regexs[61].search(r'qlaYvo.wf') + regexs[61].search(r'rssrpgYvo.wf') + regexs[61].search(r'uggc://jjj.tzk.arg/qr/?fgnghf=uvajrvf') + regexs[92].search(r' .pybfr') + regexs[92].search(r' n.svryqOgaPnapry') + regexs[92].search(r' qg') + regexs[92].search(strings[48]) + regexs[92].search(r'.nwnk') + regexs[92].search(r'.svryqOga,n.svryqOgaPnapry') + regexs[92].search(r'.svryqOgaPnapry') + regexs[92].search(r'.bow-nppbeqvba qg') + regexs[68].search(strings[77]) + regexs[68].search(r'*') + regexs[68].search(r'.pybfr') + regexs[68].search(strings[82]) + regexs[68].search(strings[83]) + regexs[68].search(strings[84]) + regexs[68].search(strings[86]) + regexs[68].search(r'qg') + regexs[68].search(r'rzorq') + regexs[68].search(r'sbez.nwnk') + regexs[68].search(strings[90]) + regexs[68].search(r'bowrpg') + regexs[93].search(r' .pybfr') + regexs[93].search(r' n.svryqOgaPnapry') + regexs[93].search(r' qg') + regexs[93].search(strings[48]) + regexs[93].search(r'.nwnk') + regexs[93].search(r'.svryqOga,n.svryqOgaPnapry') + regexs[93].search(r'.svryqOgaPnapry') + regexs[93].search(r'.bow-nppbeqvba qg') + regexs[81].search(strings[77]) + regexs[81].search(r'*') + regexs[81].search(strings[48]) + regexs[81].search(r'.pybfr') + regexs[81].search(strings[82]) + regexs[81].search(strings[83]) + regexs[81].search(strings[84]) + regexs[81].search(strings[86]) + regexs[81].search(r'qg') + regexs[81].search(r'rzorq') + regexs[81].search(r'sbez.nwnk') + regexs[81].search(strings[90]) + regexs[81].search(r'bowrpg') + regexs[94].search(r' .pybfr') + regexs[94].search(r' n.svryqOgaPnapry') + regexs[94].search(r' qg') + regexs[94].search(strings[48]) + regexs[94].search(r'.nwnk') + regexs[94].search(r'.svryqOga,n.svryqOgaPnapry') + regexs[94].search(r'.svryqOgaPnapry') + regexs[94].search(r'.bow-nppbeqvba qg') + regexs[94].search(r'[anzr=nwnkHey]') + regexs[94].search(strings[82]) + regexs[31].search(r'rf') + regexs[31].search(r'wn') + regexs[82].search(strings[77]) + regexs[82].search(r'*') + regexs[82].search(strings[48]) + regexs[82].search(r'.pybfr') + regexs[82].search(strings[82]) + regexs[82].search(strings[83]) + regexs[82].search(strings[84]) + regexs[82].search(strings[86]) + regexs[82].search(r'qg') + regexs[82].search(r'rzorq') + regexs[82].search(r'sbez.nwnk') + regexs[82].search(strings[90]) + regexs[82].search(r'bowrpg') + regexs[83].search(strings[98]) + regexs[83].search(r'shapgvba sbphf() { [angvir pbqr] }') + regexs[62].search(r'#Ybtva') + regexs[62].search(r'#Ybtva_cnffjbeq') + regexs[62].search(strings[77]) + regexs[62].search(r'#fubhgobkWf') + regexs[62].search(r'#fubhgobkWfReebe') + regexs[62].search(r'#fubhgobkWfFhpprff') + regexs[62].search(r'*') + regexs[62].search(strings[82]) + regexs[62].search(strings[83]) + regexs[62].search(strings[86]) + regexs[62].search(r'rzorq') + regexs[62].search(r'sbez.nwnk') + regexs[62].search(strings[90]) + regexs[62].search(r'bowrpg') + regexs[49].search(r'pbagrag') + regexs[24].search(strings[6]) + re.search(r'xbadhrebe', strings[63]) + re.search(r'znp', 'jva32') + re.search(r'zbmvyyn', strings[63]) + re.search(r'zfvr', strings[63]) + re.search(r'ag\s5\.1', strings[63]) + re.search(r'bcren', strings[63]) + re.search(r'fnsnev', strings[63]) + re.search(r'jva', 'jva32') + re.search(r'jvaqbjf', strings[63]) + + +def bench_regex_v8(): + block0() + block1() + block2() + block3() + block4() + block5() + block6() + block7() + block8() + block9() + block10() + block11() + + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=False) + profiler.enable() + + bench_regex_v8() + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py b/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py new file mode 100644 index 00000000..5e58dbf1 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py @@ -0,0 +1,441 @@ +""" +based on a Java version: + Based on original version written in BCPL by Dr Martin Richards + in 1981 at Cambridge University Computer Laboratory, England + and a C++ version derived from a Smalltalk version written by + L Peter Deutsch. + Java version: Copyright (C) 1995 Sun Microsystems, Inc. + Translation from C++, Mario Wolczko + Outer loop added by Alex Jacoby +""" + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +# Task IDs +I_IDLE = 1 +I_WORK = 2 +I_HANDLERA = 3 +I_HANDLERB = 4 +I_DEVA = 5 +I_DEVB = 6 + +# Packet types +K_DEV = 1000 +K_WORK = 1001 + +# Packet + +BUFSIZE = 4 + +BUFSIZE_RANGE = range(BUFSIZE) + + +class Packet(object): + + def __init__(self, l, i, k): + self.link = l + self.ident = i + self.kind = k + self.datum = 0 + self.data = [0] * BUFSIZE + + def append_to(self, lst): + self.link = None + if lst is None: + return self + else: + p = lst + next = p.link + while next is not None: + p = next + next = p.link + p.link = self + return lst + +# Task Records + + +class TaskRec(object): + pass + + +class DeviceTaskRec(TaskRec): + + def __init__(self): + self.pending = None + + +class IdleTaskRec(TaskRec): + + def __init__(self): + self.control = 1 + self.count = 10000 + + +class HandlerTaskRec(TaskRec): + + def __init__(self): + self.work_in = None + self.device_in = None + + def workInAdd(self, p): + self.work_in = p.append_to(self.work_in) + return self.work_in + + def deviceInAdd(self, p): + self.device_in = p.append_to(self.device_in) + return self.device_in + + +class WorkerTaskRec(TaskRec): + + def __init__(self): + self.destination = I_HANDLERA + self.count = 0 +# Task + + +class TaskState(object): + + def __init__(self): + self.packet_pending = True + self.task_waiting = False + self.task_holding = False + + def packetPending(self): + self.packet_pending = True + self.task_waiting = False + self.task_holding = False + return self + + def waiting(self): + self.packet_pending = False + self.task_waiting = True + self.task_holding = False + return self + + def running(self): + self.packet_pending = False + self.task_waiting = False + self.task_holding = False + return self + + def waitingWithPacket(self): + self.packet_pending = True + self.task_waiting = True + self.task_holding = False + return self + + def isPacketPending(self): + return self.packet_pending + + def isTaskWaiting(self): + return self.task_waiting + + def isTaskHolding(self): + return self.task_holding + + def isTaskHoldingOrWaiting(self): + return self.task_holding or (not self.packet_pending and self.task_waiting) + + def isWaitingWithPacket(self): + return self.packet_pending and self.task_waiting and not self.task_holding + + +tracing = False +layout = 0 + + +def trace(a): + global layout + layout -= 1 + if layout <= 0: + print() + layout = 50 + print(a, end='') + + +TASKTABSIZE = 10 + + +class TaskWorkArea(object): + + def __init__(self): + self.taskTab = [None] * TASKTABSIZE + + self.taskList = None + + self.holdCount = 0 + self.qpktCount = 0 + + +taskWorkArea = TaskWorkArea() + + +class Task(TaskState): + + def __init__(self, i, p, w, initialState, r): + self.link = taskWorkArea.taskList + self.ident = i + self.priority = p + self.input = w + + self.packet_pending = initialState.isPacketPending() + self.task_waiting = initialState.isTaskWaiting() + self.task_holding = initialState.isTaskHolding() + + self.handle = r + + taskWorkArea.taskList = self + taskWorkArea.taskTab[i] = self + + def fn(self, pkt, r): + raise NotImplementedError + + def addPacket(self, p, old): + if self.input is None: + self.input = p + self.packet_pending = True + if self.priority > old.priority: + return self + else: + p.append_to(self.input) + return old + + def runTask(self): + if self.isWaitingWithPacket(): + msg = self.input + self.input = msg.link + if self.input is None: + self.running() + else: + self.packetPending() + else: + msg = None + + return self.fn(msg, self.handle) + + def waitTask(self): + self.task_waiting = True + return self + + def hold(self): + taskWorkArea.holdCount += 1 + self.task_holding = True + return self.link + + def release(self, i): + t = self.findtcb(i) + t.task_holding = False + if t.priority > self.priority: + return t + else: + return self + + def qpkt(self, pkt): + t = self.findtcb(pkt.ident) + taskWorkArea.qpktCount += 1 + pkt.link = None + pkt.ident = self.ident + return t.addPacket(pkt, self) + + def findtcb(self, id): + t = taskWorkArea.taskTab[id] + if t is None: + raise Exception("Bad task id %d" % id) + return t + + +# DeviceTask + + +class DeviceTask(Task): + + def __init__(self, i, p, w, s, r): + Task.__init__(self, i, p, w, s, r) + + def fn(self, pkt, r): + d = r + assert isinstance(d, DeviceTaskRec) + if pkt is None: + pkt = d.pending + if pkt is None: + return self.waitTask() + else: + d.pending = None + return self.qpkt(pkt) + else: + d.pending = pkt + if tracing: + trace(pkt.datum) + return self.hold() + + +class HandlerTask(Task): + + def __init__(self, i, p, w, s, r): + Task.__init__(self, i, p, w, s, r) + + def fn(self, pkt, r): + h = r + assert isinstance(h, HandlerTaskRec) + if pkt is not None: + if pkt.kind == K_WORK: + h.workInAdd(pkt) + else: + h.deviceInAdd(pkt) + work = h.work_in + if work is None: + return self.waitTask() + count = work.datum + if count >= BUFSIZE: + h.work_in = work.link + return self.qpkt(work) + + dev = h.device_in + if dev is None: + return self.waitTask() + + h.device_in = dev.link + dev.datum = work.data[count] + work.datum = count + 1 + return self.qpkt(dev) + +# IdleTask + + +class IdleTask(Task): + + def __init__(self, i, p, w, s, r): + Task.__init__(self, i, 0, None, s, r) + + def fn(self, pkt, r): + i = r + assert isinstance(i, IdleTaskRec) + i.count -= 1 + if i.count == 0: + return self.hold() + elif i.control & 1 == 0: + i.control //= 2 + return self.release(I_DEVA) + else: + i.control = i.control // 2 ^ 0xd008 + return self.release(I_DEVB) + + +# WorkTask + + +A = ord('A') + + +class WorkTask(Task): + + def __init__(self, i, p, w, s, r): + Task.__init__(self, i, p, w, s, r) + + def fn(self, pkt, r): + w = r + assert isinstance(w, WorkerTaskRec) + if pkt is None: + return self.waitTask() + + if w.destination == I_HANDLERA: + dest = I_HANDLERB + else: + dest = I_HANDLERA + + w.destination = dest + pkt.ident = dest + pkt.datum = 0 + + for i in BUFSIZE_RANGE: # range(BUFSIZE) + w.count += 1 + if w.count > 26: + w.count = 1 + pkt.data[i] = A + w.count - 1 + + return self.qpkt(pkt) + + +def schedule(): + t = taskWorkArea.taskList + while t is not None: + if tracing: + print("tcb =", t.ident) + + if t.isTaskHoldingOrWaiting(): + t = t.link + else: + if tracing: + trace(chr(ord("0") + t.ident)) + t = t.runTask() + + +class Richards(object): + + def run(self, iterations): + for i in range(iterations): + taskWorkArea.holdCount = 0 + taskWorkArea.qpktCount = 0 + + IdleTask(I_IDLE, 1, 10000, TaskState().running(), IdleTaskRec()) + + wkq = Packet(None, 0, K_WORK) + wkq = Packet(wkq, 0, K_WORK) + WorkTask(I_WORK, 1000, wkq, TaskState( + ).waitingWithPacket(), WorkerTaskRec()) + + wkq = Packet(None, I_DEVA, K_DEV) + wkq = Packet(wkq, I_DEVA, K_DEV) + wkq = Packet(wkq, I_DEVA, K_DEV) + HandlerTask(I_HANDLERA, 2000, wkq, TaskState( + ).waitingWithPacket(), HandlerTaskRec()) + + wkq = Packet(None, I_DEVB, K_DEV) + wkq = Packet(wkq, I_DEVB, K_DEV) + wkq = Packet(wkq, I_DEVB, K_DEV) + HandlerTask(I_HANDLERB, 3000, wkq, TaskState( + ).waitingWithPacket(), HandlerTaskRec()) + + wkq = None + DeviceTask(I_DEVA, 4000, wkq, + TaskState().waiting(), DeviceTaskRec()) + DeviceTask(I_DEVB, 5000, wkq, + TaskState().waiting(), DeviceTaskRec()) + + schedule() + + if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246: + pass + else: + return False + + return True + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + richard = Richards() + richard.run(1) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_scimark/.test_noperf.py.swo b/pyperformance/data-files/benchmarks/bm_scimark/.test_noperf.py.swo new file mode 100644 index 0000000000000000000000000000000000000000..15a1c44fdd42da0055e3f2187bfab60562810c6d GIT binary patch literal 16384 zcmeI2Z;Tve9ml8Esz6I=Aw&Vq(^lHK-gWQx+Cn|=jF*;Hle?{!9>lEYW^Q-3H+#D? zo7vgkZdLG45O@JJ1%rZ#)|v`N6ET{gmK5ZLh#{up8^Hf0S`%Iv=#=f+ z;Ee6&XDgOJN3fEsK{2zw>SU;s5`w^Znme8pcWZD?A2=p#c+c=2F8r z4tK&Ga69B+JG>v(!E$(Ig<(7eKZnEc4fr~I60V1<;VM`PCzl(>vv33sKmqbF2BYvn zxEx-)#4uif=iwLdD0~H)Fa>+z21voXVF~>CV#9a_9)+*LJnV<9umv{5m0-Y27g1mM z4%`K0*bVQ6Yv5{l{auFfJNPX;2}j`|)S(EI&<`u%^g9jX5AYQH03Lz+VG<@_8?1&^ zaP}Rv3w{Xq!M)IgJ+J{@US=5ofWO1@@B};r--e@b7c^lvTnAUenYUvL&%w{&VR#6> z0H24?fd@8x0zLvC025Zj(_GyA6n+9fh9lrY1Ussf<<{i4EBvY@uzlAmx9UeN9U2nQjJ^?C-6>OCk-m-p%-rrC!;0Y6!g0^~C>WtQs$ zYJ5Odo&8=A))(G4dMaa`QFh14F)EqIklEAX9$*<~17VufvJXI>xn zwEl%tj#h?s5wES0GclDbTKT~9wF0r`m+Ps#S8e8GO5}>ZS24#!XWe48Jc%~(&v@2x zrn9BewAw_Q!iQ;EI-V`*Xd`YcVG+DkYAbG*WT=L9jhl*@<18|pq)9C^hFXacQ*qo$ znF~z6c2dh^JUd4%s1Lf@`RamnDPisn3lJ}o4W-jexxuJW(``3V4JLb(F70QmWlPm* z>1_Gdj|($bWvZ0AD(-hr!?5d|1D4E6RkWBZ1vO*mtvb_{Ie5VKy>Lvg4M&GmoVw{! zrTO8K)~>ehe;uz%3pJ69vS3*=ZDWa&Pf28O3>}XCP=qz3KBSm4@o3`2L(OD3i29v6 z=}vt^$-}}Ws|=r5R$Y8am!n5e$BXX&Xjp_}VNAw^IoY085|U0x&Dzes*?@jX%{zr) zR3Qe}$kOyN}PZP1={;l`p^c&)&!y9L|Nu`%tp z`xr?vhfJ0&sc?sAsTea}xMZSu1N#PZrpb3xjq0J<(Z5MMWd(8VMzF)H&y;PmBY)#u ziK3`pH9M-tDi~=SuT*PGTd)kJ)0@M!Gn-Vg;3YSucjo0kz*M z4=CT8AD~)<8hl6V>w=L+ViqeOIUJd04w}>gyECS{2Au21mJbnIjL8@7)e?cgI&QSJ zn@c1`WTlL>lo6HZ`i3OQCvxJ;)*g%2hT1;shqGR4!>ShTHF__W{NjE{Tt|Bq&pa&N zJX*WD0XW=t&6HLKg7=X**70&dhz%CunW>~6`bW<{}(s`KZ1jB z4`g5xCSVZW1Iyr#objK8qi`F{!ga6}w!kVl&Ds7{kUN0m@G#sBw}RXO?11&K5?<$Q z|0nn*JPqH6BG~Y8=!cDP1)SoX{|tN&z6*z74n7Q*z{PM8oZ@WXx&wHe@NtkkfI~0~ zatAO7tKk&q_?O`YkUM}U;6Zo*z6y81E#QL%dte;;;YH5#zkz4r*KiDOhcCfxFawXXiTq$0yK&aB?xg#YJ*4kX#HT7X$HiA-NdP_ae!~ uKyop_v`8)nl8b@x;vl&g_^)0JM3-@k{(I1MdQZ;($@#x^OZb0#{{Iin*ADjp literal 0 HcmV?d00001 diff --git a/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py b/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py new file mode 100644 index 00000000..6ac624f8 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py @@ -0,0 +1,425 @@ +from array import array +import math +import subprocess +import pyperf + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +class Array2D(object): + + def __init__(self, w, h, data=None): + self.width = w + self.height = h + self.data = array('d', [0]) * (w * h) + if data is not None: + self.setup(data) + + def _idx(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + return y * self.width + x + raise IndexError + + def __getitem__(self, x_y): + (x, y) = x_y + return self.data[self._idx(x, y)] + + def __setitem__(self, x_y, val): + (x, y) = x_y + self.data[self._idx(x, y)] = val + + def setup(self, data): + for y in range(self.height): + for x in range(self.width): + self[x, y] = data[y][x] + return self + + def indexes(self): + for y in range(self.height): + for x in range(self.width): + yield x, y + + def copy_data_from(self, other): + self.data[:] = other.data[:] + + +class Random(object): + MDIG = 32 + ONE = 1 + m1 = (ONE << (MDIG - 2)) + ((ONE << (MDIG - 2)) - ONE) + m2 = ONE << MDIG // 2 + dm1 = 1.0 / float(m1) + + def __init__(self, seed): + self.initialize(seed) + self.left = 0.0 + self.right = 1.0 + self.width = 1.0 + self.haveRange = False + + def initialize(self, seed): + + self.seed = seed + seed = abs(seed) + jseed = min(seed, self.m1) + if (jseed % 2 == 0): + jseed -= 1 + k0 = 9069 % self.m2 + k1 = 9069 / self.m2 + j0 = jseed % self.m2 + j1 = jseed / self.m2 + self.m = array('d', [0]) * 17 + for iloop in range(17): + jseed = j0 * k0 + j1 = (jseed / self.m2 + j0 * k1 + j1 * k0) % (self.m2 / 2) + j0 = jseed % self.m2 + self.m[iloop] = j0 + self.m2 * j1 + self.i = 4 + self.j = 16 + + def nextDouble(self): + I, J, m = self.i, self.j, self.m + k = m[I] - m[J] + if (k < 0): + k += self.m1 + self.m[J] = k + + if (I == 0): + I = 16 + else: + I -= 1 + self.i = I + + if (J == 0): + J = 16 + else: + J -= 1 + self.j = J + + if (self.haveRange): + return self.left + self.dm1 * float(k) * self.width + else: + return self.dm1 * float(k) + + def RandomMatrix(self, a): + for x, y in a.indexes(): + a[x, y] = self.nextDouble() + return a + + def RandomVector(self, n): + return array('d', [self.nextDouble() for i in range(n)]) + + +def copy_vector(vec): + # Copy a vector created by Random.RandomVector() + vec2 = array('d') + vec2[:] = vec[:] + return vec2 + + +class ArrayList(Array2D): + + def __init__(self, w, h, data=None): + self.width = w + self.height = h + self.data = [array('d', [0]) * w for y in range(h)] + if data is not None: + self.setup(data) + + def __getitem__(self, idx): + if isinstance(idx, tuple): + return self.data[idx[1]][idx[0]] + else: + return self.data[idx] + + def __setitem__(self, idx, val): + if isinstance(idx, tuple): + self.data[idx[1]][idx[0]] = val + else: + self.data[idx] = val + + def copy_data_from(self, other): + for l1, l2 in zip(self.data, other.data): + l1[:] = l2 + + +def SOR_execute(omega, G, cycles, Array): + for p in range(cycles): + for y in range(1, G.height - 1): + for x in range(1, G.width - 1): + G[x, y] = (omega * 0.25 * (G[x, y - 1] + G[x, y + 1] + G[x - 1, y] + + G[x + 1, y]) + + (1.0 - omega) * G[x, y]) + + +def bench_SOR( n, cycles, Array): + t0 = pyperf.perf_counter() + + G = Array(n, n) + SOR_execute(1.25, G, cycles, Array) + + return pyperf.perf_counter() - t0 + + +def SparseCompRow_matmult(M, y, val, row, col, x, num_iterations): + range_it = range(num_iterations) + t0 = pyperf.perf_counter() + + for _ in range_it: + for r in range(M): + sa = 0.0 + for i in range(row[r], row[r + 1]): + sa += x[col[i]] * val[i] + y[r] = sa + + return pyperf.perf_counter() - t0 + + +def bench_SparseMatMult(cycles, N, nz): + x = array('d', [0]) * N + y = array('d', [0]) * N + + nr = nz // N + anz = nr * N + val = array('d', [0]) * anz + col = array('i', [0]) * nz + row = array('i', [0]) * (N + 1) + + row[0] = 0 + for r in range(N): + rowr = row[r] + step = r // nr + row[r + 1] = rowr + nr + if step < 1: + step = 1 + for i in range(nr): + col[rowr + i] = i * step + + return SparseCompRow_matmult(N, y, val, row, col, x, cycles) + + +def MonteCarlo(Num_samples): + rnd = Random(113) + under_curve = 0 + for count in range(Num_samples): + x = rnd.nextDouble() + y = rnd.nextDouble() + if x * x + y * y <= 1.0: + under_curve += 1 + return float(under_curve) / Num_samples * 4.0 + + +def bench_MonteCarlo(Num_samples): + t0 = pyperf.perf_counter() + MonteCarlo(Num_samples) + + return pyperf.perf_counter() - t0 + + +def LU_factor(A, pivot): + M, N = A.height, A.width + minMN = min(M, N) + for j in range(minMN): + jp = j + t = abs(A[j][j]) + for i in range(j + 1, M): + ab = abs(A[i][j]) + if ab > t: + jp = i + t = ab + pivot[j] = jp + + if A[jp][j] == 0: + raise Exception("factorization failed because of zero pivot") + + if jp != j: + A[j], A[jp] = A[jp], A[j] + + if j < M - 1: + recp = 1.0 / A[j][j] + for k in range(j + 1, M): + A[k][j] *= recp + + if j < minMN - 1: + for ii in range(j + 1, M): + for jj in range(j + 1, N): + A[ii][jj] -= A[ii][j] * A[j][jj] + + +def LU(lu, A, pivot): + lu.copy_data_from(A) + LU_factor(lu, pivot) + + +def bench_LU(cycles, N): + rnd = Random(7) + A = rnd.RandomMatrix(ArrayList(N, N)) + lu = ArrayList(N, N) + pivot = array('i', [0]) * N + range_it = range(cycles) + t0 = pyperf.perf_counter() + + for _ in range_it: + LU(lu, A, pivot) + + return pyperf.perf_counter() - t0 + + +def int_log2(n): + k = 1 + log = 0 + while k < n: + k *= 2 + log += 1 + if n != 1 << log: + raise Exception("FFT: Data length is not a power of 2: %s" % n) + return log + + +def FFT_num_flops(N): + return (5.0 * N - 2) * int_log2(N) + 2 * (N + 1) + + +def FFT_transform_internal(N, data, direction): + n = N // 2 + bit = 0 + dual = 1 + if n == 1: + return + + logn = int_log2(n) + if N == 0: + return + FFT_bitreverse(N, data) + + # apply fft recursion + # this loop executed int_log2(N) times + bit = 0 + while bit < logn: + w_real = 1.0 + w_imag = 0.0 + theta = 2.0 * direction * math.pi / (2.0 * float(dual)) + s = math.sin(theta) + t = math.sin(theta / 2.0) + s2 = 2.0 * t * t + for b in range(0, n, 2 * dual): + i = 2 * b + j = 2 * (b + dual) + wd_real = data[j] + wd_imag = data[j + 1] + data[j] = data[i] - wd_real + data[j + 1] = data[i + 1] - wd_imag + data[i] += wd_real + data[i + 1] += wd_imag + for a in range(1, dual): + tmp_real = w_real - s * w_imag - s2 * w_real + tmp_imag = w_imag + s * w_real - s2 * w_imag + w_real = tmp_real + w_imag = tmp_imag + for b in range(0, n, 2 * dual): + i = 2 * (b + a) + j = 2 * (b + a + dual) + z1_real = data[j] + z1_imag = data[j + 1] + wd_real = w_real * z1_real - w_imag * z1_imag + wd_imag = w_real * z1_imag + w_imag * z1_real + data[j] = data[i] - wd_real + data[j + 1] = data[i + 1] - wd_imag + data[i] += wd_real + data[i + 1] += wd_imag + bit += 1 + dual *= 2 + + +def FFT_bitreverse(N, data): + n = N // 2 + nm1 = n - 1 + j = 0 + for i in range(nm1): + ii = i << 1 + jj = j << 1 + k = n >> 1 + if i < j: + tmp_real = data[ii] + tmp_imag = data[ii + 1] + data[ii] = data[jj] + data[ii + 1] = data[jj + 1] + data[jj] = tmp_real + data[jj + 1] = tmp_imag + while k <= j: + j -= k + k >>= 1 + j += k + + +def FFT_transform(N, data): + FFT_transform_internal(N, data, -1) + + +def FFT_inverse(N, data): + n = N / 2 + norm = 0.0 + FFT_transform_internal(N, data, +1) + norm = 1 / float(n) + for i in range(N): + data[i] *= norm + + +def bench_FFT(N, cycles): + twoN = 2 * N + init_vec = Random(7).RandomVector(twoN) + + x = copy_vector(init_vec) + for i in range(cycles): + FFT_transform(twoN, x) + FFT_inverse(twoN, x) + + +BENCHMARKS = { + # function name => arguments + 'sor': (bench_SOR, 100, 10, Array2D), + 'sparse_mat_mult': (bench_SparseMatMult, 10, 1000, 50 * 1000), + 'monte_carlo': (bench_MonteCarlo, 100 * 1000,), + 'lu': (bench_LU, 100, 10), + 'fft': (bench_FFT, 1024, 50), +} + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("benchmark", + nargs='?', + choices=sorted(BENCHMARKS)) + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if args.benchmark: + benchmarks = (args.benchmark,) + else: + benchmarks = sorted(BENCHMARKS) + + for bench in benchmarks: + name = 'scimark_%s' % bench + func = BENCHMARKS[bench][0] + options = [arg for arg in BENCHMARKS[bench]][1:] + func(*options) + + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py b/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py new file mode 100644 index 00000000..a8d39e8e --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py @@ -0,0 +1,84 @@ +""" +MathWorld: "Hundred-Dollar, Hundred-Digit Challenge Problems", Challenge #3. +http://mathworld.wolfram.com/Hundred-DollarHundred-DigitChallengeProblems.html + +The Computer Language Benchmarks Game +http://benchmarksgame.alioth.debian.org/u64q/spectralnorm-description.html#spectralnorm + +Contributed by Sebastien Loisel +Fixed by Isaac Gouy +Sped up by Josh Goldfoot +Dirtily sped up by Simon Descarpentries +Concurrency by Jason Stitt +""" + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +DEFAULT_N = 130 + + +def eval_A(i, j): + return 1.0 / ((i + j) * (i + j + 1) // 2 + i + 1) + + +def eval_times_u(func, u): + return [func((i, u)) for i in range(len(list(u)))] + + +def eval_AtA_times_u(u): + return eval_times_u(part_At_times_u, eval_times_u(part_A_times_u, u)) + + +def part_A_times_u(i_u): + i, u = i_u + partial_sum = 0 + for j, u_j in enumerate(u): + partial_sum += eval_A(i, j) * u_j + return partial_sum + + +def part_At_times_u(i_u): + i, u = i_u + partial_sum = 0 + for j, u_j in enumerate(u): + partial_sum += eval_A(j, i) * u_j + return partial_sum + + +def bench_spectral_norm(): + u = [1] * DEFAULT_N + + for dummy in range(10): + v = eval_AtA_times_u(u) + u = eval_AtA_times_u(v) + + vBv = vv = 0 + + for ue, ve in zip(u, v): + vBv += ue * ve + vv += ve * ve + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + bench_spectral_norm() + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py new file mode 100644 index 00000000..e986e99a --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py @@ -0,0 +1,108 @@ +from sqlalchemy import Column, ForeignKey, Integer, String +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import relationship, sessionmaker +from sqlalchemy import create_engine + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +Base = declarative_base() + + +class Person(Base): + __tablename__ = 'person' + # Here we define columns for the table person + # Notice that each column is also a normal Python instance attribute. + id = Column(Integer, primary_key=True) + name = Column(String(250), nullable=False) + + +class Address(Base): + __tablename__ = 'address' + # Here we define columns for the table address. + # Notice that each column is also a normal Python instance attribute. + id = Column(Integer, primary_key=True) + street_name = Column(String(250)) + street_number = Column(String(250)) + post_code = Column(String(250), nullable=False) + person_id = Column(Integer, ForeignKey('person.id')) + person = relationship(Person) + + +# Create an engine that stores data in the local directory's +# sqlalchemy_example.db file. +engine = create_engine('sqlite://') + +# Create all tables in the engine. This is equivalent to "Create Table" +# statements in raw SQL. +Base.metadata.create_all(engine) + + +# Bind the engine to the metadata of the Base class so that the +# declaratives can be accessed through a DBSession instance +Base.metadata.bind = engine + +DBSession = sessionmaker(bind=engine) +# A DBSession() instance establishes all conversations with the database +# and represents a "staging zone" for all the objects loaded into the +# database session object. Any change made against the objects in the +# session won't be persisted into the database until you call +# session.commit(). If you're not happy about the changes, you can +# revert all of them back to the last commit by calling +# session.rollback() +session = DBSession() + + +# add 'npeople' people to the database + +def bench_sqlalchemy(npeople): + total_dt = 0.0 + + # drop rows created by the previous benchmark + session.query(Person).delete(synchronize_session=False) + session.query(Address).delete(synchronize_session=False) + + # Run the benchmark once + for i in range(npeople): + # Insert a Person in the person table + new_person = Person(name="name %i" % i) + session.add(new_person) + session.commit() + + # Insert an Address in the address table + new_address = Address(post_code='%05i' % i, person=new_person) + session.add(new_address) + session.commit() + + # do 100 queries per insert + for i in range(npeople): + session.query(Person).all() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--rows", + type=int, + default=100, + help="Number of rows (default: 100)") + + args = parser.parse_args() + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_sqlalchemy(args.rows) + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py new file mode 100644 index 00000000..5fb2b54e --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py @@ -0,0 +1,98 @@ + +from sqlalchemy import Column, ForeignKey, Integer, String, Table, MetaData +from sqlalchemy.orm import sessionmaker +from sqlalchemy import create_engine + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +metadata = MetaData() + +Person = Table('person', metadata, + Column('id', Integer, primary_key=True), + Column('name', String(250), nullable=False)) + +Address = Table('address', metadata, + Column('id', Integer, primary_key=True), + Column('street_name', String(250)), + Column('street_number', String(250)), + Column('post_code', String(250), nullable=False), + Column('person_id', Integer, ForeignKey('person.id'))) + +# Create an engine that stores data in the local directory's +# sqlalchemy_example.db file. +engine = create_engine('sqlite://') + +# Create all tables in the engine. This is equivalent to "Create Table" +# statements in raw SQL. +metadata.create_all(engine) + + +# Bind the engine to the metadata of the Base class so that the +# declaratives can be accessed through a DBSession instance +metadata.bind = engine + +DBSession = sessionmaker(bind=engine) +# A DBSession() instance establishes all conversations with the database +# and represents a "staging zone" for all the objects loaded into the +# database session object. Any change made against the objects in the +# session won't be persisted into the database until you call +# session.commit(). If you're not happy about the changes, you can +# revert all of them back to the last commit by calling +# session.rollback() +session = DBSession() + + +# add 'npeople' people to the database +def bench_sqlalchemy(npeople): + # drop rows created by the previous benchmark + cur = Person.delete() + cur.execute() + cur = Address.delete() + cur.execute() + + # Run the benchmark once + for i in range(npeople): + # Insert a Person in the person table + new_person = Person.insert() + new_person.execute(name="name %i" % i) + + # Insert an Address in the address table + new_address = Address.insert() + new_address.execute(post_code='%05i' % i) + + # do 'npeople' queries per insert + for i in range(npeople): + cur = Person.select() + cur.execute() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--rows", + type=int, + default=100, + help="Number of rows (default: 100)") + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + bench_sqlalchemy(args.rows) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + + diff --git a/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py new file mode 100644 index 00000000..77ebc677 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py @@ -0,0 +1,69 @@ +""" +SQLite benchmark. + +The goal of the benchmark is to test CFFI performance and going back and forth +between SQLite and Python a lot. Therefore the queries themselves are really +simple. +""" + +import sqlite3 +import math + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +class AvgLength(object): + + def __init__(self): + self.sum = 0 + self.count = 0 + + def step(self, x): + if x is not None: + self.count += 1 + self.sum += len(x) + + def finalize(self): + return self.sum / float(self.count) + + +def bench_sqlite(): + conn = sqlite3.connect(":memory:") + conn.execute('create table cos (x, y, z);') + for i in range(1): + cos_i = math.cos(i) + conn.execute('insert into cos values (?, ?, ?)', + [i, cos_i, str(i)]) + + conn.create_function("cos", 1, math.cos) + for x, cosx1, cosx2 in conn.execute("select x, cos(x), y from cos"): + assert math.cos(x) == cosx1 == cosx2 + + conn.create_aggregate("avglength", 1, AvgLength) + cursor = conn.execute("select avglength(z) from cos;") + cursor.fetchone()[0] + conn.execute("delete from cos;") + conn.close() + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + bench_sqlite() + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py b/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py new file mode 100644 index 00000000..f12cb456 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py @@ -0,0 +1,100 @@ +# coding: UTF-8 +""" Telco Benchmark for measuring the performance of decimal calculations + +- http://speleotrove.com/decimal/telco.html +- http://speleotrove.com/decimal/telcoSpec.html + +A call type indicator, c, is set from the bottom (least significant) bit of the duration (hence c is 0 or 1). +A rate, r, is determined from the call type. Those calls with c=0 have a low r: 0.0013; the remainder (‘distance calls’) have a ‘premium’ r: 0.00894. (The rates are, very roughly, in Euros or dollarates per second.) +A price, p, for the call is then calculated (p=r*n). This is rounded to exactly 2 fractional digits using round-half-even (Banker’s round to nearest). +A basic tax, b, is calculated: b=p*0.0675 (6.75%). This is truncated to exactly 2 fractional digits (round-down), and the total basic tax variable is then incremented (sumB=sumB+b). +For distance calls: a distance tax, d, is calculated: d=p*0.0341 (3.41%). This is truncated to exactly 2 fractional digits (round-down), and then the total distance tax variable is incremented (sumD=sumD+d). +The total price, t, is calculated (t=p+b, and, if a distance call, t=t+d). +The total prices variable is incremented (sumT=sumT+t). +The total price, t, is converted to a string, s. + +""" + +from decimal import ROUND_HALF_EVEN, ROUND_DOWN, Decimal, getcontext, Context +import io +import os +from struct import unpack + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +def rel_path(*path): + return os.path.join(os.path.dirname(__file__), *path) + + +def bench_telco(filename): + getcontext().rounding = ROUND_DOWN + rates = list(map(Decimal, ('0.0013', '0.00894'))) + twodig = Decimal('0.01') + Banker = Context(rounding=ROUND_HALF_EVEN) + basictax = Decimal("0.0675") + disttax = Decimal("0.0341") + + with open(filename, "rb") as infil: + data = infil.read() + + infil = io.BytesIO(data) + outfil = io.StringIO() + + infil.seek(0) + + sumT = Decimal("0") # sum of total prices + sumB = Decimal("0") # sum of basic tax + sumD = Decimal("0") # sum of 'distance' tax + + for i in range(5000): + datum = infil.read(8) + if datum == '': + break + n, = unpack('>Q', datum) + calltype = n & 1 + r = rates[calltype] + p = Banker.quantize(r * n, twodig) + + b = p * basictax + b = b.quantize(twodig) + sumB += b + + t = p + b + + if calltype: + d = p * disttax + d = d.quantize(twodig) + sumD += d + t += d + + sumT += t + print(t, file=outfil) + + outfil.seek(0) + outfil.truncate() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + filename = rel_path("data", "telco-bench.b") + bench_telco(filename) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py b/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py new file mode 100644 index 00000000..c8550277 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py @@ -0,0 +1,116 @@ + +"""Test the performance of simple HTTP serving and client using the Tornado +framework. + +A trivial "application" is generated which generates a number of chunks of +data as a HTTP response's body. +""" + +import sys +import socket + +from tornado.httpclient import AsyncHTTPClient +from tornado.httpserver import HTTPServer +from tornado.gen import coroutine +from tornado.ioloop import IOLoop +from tornado.netutil import bind_sockets +from tornado.web import RequestHandler, Application + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +HOST = "127.0.0.1" +FAMILY = socket.AF_INET + +CHUNK = b"Hello world\n" * 1000 +NCHUNKS = 5 + +CONCURRENCY = 150 + + +class MainHandler(RequestHandler): + + @coroutine + def get(self): + for i in range(NCHUNKS): + self.write(CHUNK) + yield self.flush() + + def compute_etag(self): + # Overriden to avoid stressing hashlib in this benchmark + return None + + +def make_application(): + return Application([ + (r"/", MainHandler), + ]) + + +def make_http_server(request_handler): + server = HTTPServer(request_handler) + sockets = bind_sockets(0, HOST, family=FAMILY) + assert len(sockets) == 1 + server.add_sockets(sockets) + sock = sockets[0] + return server, sock + + +def bench_tornado(): + server, sock = make_http_server(make_application()) + host, port = sock.getsockname() + url = "http://%s:%s/" % (host, port) + namespace = {} + + @coroutine + def run_client(): + client = AsyncHTTPClient() + + futures = [client.fetch(url) for j in range(CONCURRENCY)] + for fut in futures: + resp = yield fut + buf = resp.buffer + buf.seek(0, 2) + assert buf.tell() == len(CHUNK) * NCHUNKS + + client.close() + + IOLoop.current().run_sync(run_client) + server.stop() + + + +if __name__ == "__main__": + # 3.8 changed the default event loop to ProactorEventLoop which doesn't + # implement everything required by tornado and breaks this benchmark. + # Restore the old WindowsSelectorEventLoop default for now. + # https://bugs.python.org/issue37373 + # https://github.com/python/pyperformance/issues/61 + # https://github.com/tornadoweb/tornado/pull/2686 + + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if sys.platform == 'win32' and sys.version_info[:2] >= (3, 8): + import asyncio + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + + bench_tornado() + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py b/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py new file mode 100644 index 00000000..feaa5d72 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py @@ -0,0 +1,465 @@ +"""Microbenchmark for Python's sequence unpacking.""" + + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +def do_unpacking(loops, to_unpack): + range_it = range(loops) + + for _ in range_it: + # 400 unpackings + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + a, b, c, d, e, f, g, h, i, j = to_unpack + + + +def bench_tuple_unpacking(loops): + x = tuple(range(10)) + return do_unpacking(loops, x) + + +def bench_list_unpacking(loops): + x = list(range(10)) + + return do_unpacking(loops, x) + + +def bench_all(loops): + bench_tuple_unpacking(loops) + bench_list_unpacking(loops) + + + +if __name__ == "__main__": + benchmarks = {"tuple": bench_tuple_unpacking, + "list": bench_list_unpacking} + + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("benchmark", + nargs="?", + choices=sorted(benchmarks)) + + options = parser.parse_args() + profiler = Profile(builtins=options.builtins) + profiler.enable() + + if options.benchmark: + func = benchmarks[options.benchmark] + name += "_%s" % options.benchmark + else: + func = bench_all + + func(loops=400) + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(options.amount) + ps.dump_stats("test.prof") + diff --git a/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py b/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py new file mode 100644 index 00000000..52b30e62 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py @@ -0,0 +1,296 @@ + +"""Benchmark script for testing the performance of ElementTree. + +This is intended to support Unladen Swallow's pyperf.py. + +This will have ElementTree, cElementTree and lxml (if available) +parse a generated XML file, search it, create new XML trees from +it and serialise the result. +""" + +import io +import os +import sys +import tempfile + +from collections import defaultdict + +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + + +__author__ = "stefan_ml@behnel.de (Stefan Behnel)" + +FALLBACK_ETMODULE = 'xml.etree.ElementTree' + + +def build_xml_tree(etree): + SubElement = etree.SubElement + root = etree.Element('root') + + # create a couple of repetitive broad subtrees + for c in range(50): + child = SubElement(root, 'child-%d' % c, + tag_type="child") + for i in range(100): + SubElement(child, 'subchild').text = 'LEAF-%d-%d' % (c, i) + + # create a deep subtree + deep = SubElement(root, 'deepchildren', tag_type="deepchild") + for i in range(50): + deep = SubElement(deep, 'deepchild') + SubElement(deep, 'deepleaf', tag_type="leaf").text = "LEAF" + + # store the number of elements for later + nb_elems = sum(1 for elem in root.iter()) + root.set('nb-elems', str(nb_elems)) + + return root + + +def process(etree, xml_root=None): + SubElement = etree.SubElement + + if xml_root is not None: + root = xml_root + else: + root = build_xml_tree(etree) + + # find*() + found = sum(child.find('.//deepleaf') is not None + for child in root) + if found != 1: + raise RuntimeError("find() failed") + + text = 'LEAF-5-99' + found = any(1 for child in root + for el in child.iterfind('.//subchild') + if el.text == text) + if not found: + raise RuntimeError("iterfind() failed") + + found = sum(el.text == 'LEAF' + for el in root.findall('.//deepchild/deepleaf')) + if found != 1: + raise RuntimeError("findall() failed") + + # tree creation based on original tree + dest = etree.Element('root2') + target = SubElement(dest, 'result-1') + for child in root: + SubElement(target, child.tag).text = str(len(child)) + if len(target) != len(root): + raise RuntimeError("transform #1 failed") + + target = SubElement(dest, 'result-2') + for child in root.iterfind('.//subchild'): + SubElement(target, child.tag, attr=child.text).text = "found" + + if (len(target) < len(root) + or not all(el.text == 'found' + for el in target.iterfind('subchild'))): + raise RuntimeError("transform #2 failed") + + # moving subtrees around + orig_len = len(root[0]) + new_root = root.makeelement('parent', {}) + new_root[:] = root[0] + el = root[0] + del el[:] + for child in new_root: + if child is not None: + el.append(child) + if len(el) != orig_len: + raise RuntimeError("child moving failed") + + # check iteration tree consistency + d = defaultdict(list) + for child in root: + tags = d[child.get('tag_type')] + for sub in child.iter(): + tags.append(sub) + + check_dict = dict((n, iter(ch)) for n, ch in d.items()) + target = SubElement(dest, 'transform-2') + for child in root: + tags = check_dict[child.get('tag_type')] + for sub in child.iter(): + # note: explicit object identity check to make sure + # users can properly keep state in the tree + if sub is not next(tags): + raise RuntimeError("tree iteration consistency check failed") + SubElement(target, sub.tag).text = 'worked' + + # final probability check for serialisation (we added enough content + # to make the result tree larger than the original) + orig = etree.tostring(root, encoding='utf8') + result = etree.tostring(dest, encoding='utf8') + if (len(result) < len(orig) + or b'worked' not in result + or b'>LEAF<' not in orig): + raise RuntimeError("serialisation probability check failed") + return result + + +def bench_iterparse(etree, xml_file, xml_data, xml_root): + for _ in range(10): + it = etree.iterparse(xml_file, ('start', 'end')) + events1 = [(event, elem.tag) for event, elem in it] + it = etree.iterparse(io.BytesIO(xml_data), ('start', 'end')) + events2 = [(event, elem.tag) for event, elem in it] + nb_elems = int(xml_root.get('nb-elems')) + if len(events1) != 2 * nb_elems or events1 != events2: + raise RuntimeError("parsing check failed:\n%r\n%r\n" % + (len(events1), events2[:10])) + + +def bench_parse(etree, xml_file, xml_data, xml_root): + for _ in range(30): + root1 = etree.parse(xml_file).getroot() + root2 = etree.fromstring(xml_data) + result1 = etree.tostring(root1) + result2 = etree.tostring(root2) + if result1 != result2: + raise RuntimeError("serialisation check failed") + + +def bench_process(etree, xml_file, xml_data, xml_root): + result1 = process(etree, xml_root=xml_root) + result2 = process(etree, xml_root=xml_root) + if result1 != result2 or b'>found<' not in result2: + raise RuntimeError("serialisation check failed") + + +def bench_generate(etree, xml_file, xml_data, xml_root): + output = [] + for _ in range(10): + root = build_xml_tree(etree) + output.append(etree.tostring(root)) + + length = None + for xml in output: + if length is None: + length = len(xml) + elif length != len(xml): + raise RuntimeError("inconsistent output detected") + if b'>LEAF<' not in xml: + raise RuntimeError("unexpected output detected") + + +def bench_etree(etree, bench_func): + xml_root = build_xml_tree(etree) + xml_data = etree.tostring(xml_root) + + # not using NamedTemporaryFile() here as re-opening it is not portable + tf, file_path = tempfile.mkstemp() + try: + etree.ElementTree(xml_root).write(file_path) + + bench_func(etree, file_path, xml_data, xml_root) + + finally: + try: + os.close(tf) + except EnvironmentError: + pass + try: + os.unlink(file_path) + except EnvironmentError: + pass + + + + +BENCHMARKS = 'parse iterparse generate process'.split() + + +if __name__ == "__main__": + default_etmodule = "xml.etree.ElementTree" + + # On Python 3, xml.etree.cElementTree is a deprecated alias + # to xml.etree.ElementTree + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("--etree-module", + default=None, + metavar="FQMN", + help="Select an ElementTree module to use " + "(fully qualified module name). " + "Default is '%s'" % default_etmodule) + parser.add_argument("--no-accelerator", + action="store_true", + default=False, + help="Disable the '_elementree' accelerator module " + "for ElementTree.") + parser.add_argument("benchmark", + nargs='?', + choices=BENCHMARKS) + + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + if not args.etree_module: + if args.no_accelerator: + args.etree_module = FALLBACK_ETMODULE + else: + args.etree_module = default_etmodule + if args.no_accelerator: + # prevent C accelerator from being used in 3.3 + sys.modules['_elementtree'] = None + import xml.etree.ElementTree as et + if et.SubElement.__module__ != 'xml.etree.ElementTree': + raise RuntimeError("Unexpected C accelerator for ElementTree") + + try: + from importlib import import_module + except ImportError: + def import_module(module_name): + __import__(module_name) + return sys.modules[module_name] + + try: + etree_module = import_module(args.etree_module) + except ImportError: + if args.etree_module != default_etmodule: + raise + etree_module = import_module(FALLBACK_ETMODULE) + + # Fill elementtree_module metadata: check if the accelerator is used + module = etree_module.__name__ + # xml.etree.ElementTree._Element_Py was added to Python 3.4 + if hasattr(etree_module, '_Element_Py'): + accelerator = (etree_module.Element is not etree_module._Element_Py) + else: + if args.no_accelerator: + accelerator = False + else: + accelerator = True + if accelerator: + module += ' (with C accelerator)' + else: + module += ' (pure Python)' + + if args.benchmark: + benchmarks = (options.benchmark,) + else: + benchmarks = BENCHMARKS + + # Run the benchmark + for bench in benchmarks: + bench_func = globals()['bench_%s' % bench] + bench_etree(etree_module, bench_func) + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + From 10f14e2be79b1b605e3278122535a0fe600e03f9 Mon Sep 17 00:00:00 2001 From: sasha Date: Tue, 26 Apr 2022 12:21:07 +0300 Subject: [PATCH 2/4] add test_noperf.py for bm_sympy --- .../benchmarks/bm_sympy/test_noperf.py | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py diff --git a/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py new file mode 100644 index 00000000..6bb6391e --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py @@ -0,0 +1,76 @@ +from argparse import ArgumentParser +from cProfile import Profile +from pstats import Stats, SortKey + +from sympy import expand, symbols, integrate, tan, summation +from sympy.core.cache import clear_cache + + +def bench_expand(): + x, y, z = symbols('x y z') + expand((1 + x + y + z) ** 20) + + +def bench_integrate(): + x, y = symbols('x y') + f = (1 / tan(x)) ** 10 + return integrate(f, x) + + +def bench_sum(): + x, i = symbols('x i') + summation(x ** i / i, (i, 1, 400)) + + +def bench_str(): + x, y, z = symbols('x y z') + str(expand((x + 2 * y + 3 * z) ** 30)) + + +def bench_sympy(funnc): + for _ in range(1): + # Don't benchmark clear_cache(), exclude it of the benchmark + clear_cache() + func() + + + +BENCHMARKS = ("expand", "integrate", "sum", "str") + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-b", "--builtins", + action="store_false", + help="option for cProfile.Profile() class") + parser.add_argument("-a", "--amount", + type=int, + default=20, + help="number of cumbersome functions") + parser.add_argument("benchmark", nargs='?', + choices=BENCHMARKS) + args = parser.parse_args() + + profiler = Profile(builtins=args.builtins) + profiler.enable() + + import gc + gc.disable() + + if args.benchmark: + benchmarks = (args.benchmark,) + else: + benchmarks = BENCHMARKS + + for bench in benchmarks: + name = 'sympy_%s' % bench + func = globals()['bench_' + bench] + bench_sympy(func) + + + profiler.disable() + ps = Stats(profiler).sort_stats(SortKey.TIME) + + ps.print_stats(args.amount) + ps.dump_stats("test.prof") + From a7a31d81b6c56e22653e619868876e52d214a67c Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 27 Apr 2022 11:54:11 +0300 Subject: [PATCH 3/4] deleted IDE settings --- pyperformance/data-files/benchmarks/.idea/.gitignore | 8 -------- .../data-files/benchmarks/.idea/benchmarks.iml | 12 ------------ .../.idea/inspectionProfiles/profiles_settings.xml | 6 ------ pyperformance/data-files/benchmarks/.idea/misc.xml | 4 ---- .../data-files/benchmarks/.idea/modules.xml | 8 -------- pyperformance/data-files/benchmarks/.idea/vcs.xml | 6 ------ 6 files changed, 44 deletions(-) delete mode 100644 pyperformance/data-files/benchmarks/.idea/.gitignore delete mode 100644 pyperformance/data-files/benchmarks/.idea/benchmarks.iml delete mode 100644 pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml delete mode 100644 pyperformance/data-files/benchmarks/.idea/misc.xml delete mode 100644 pyperformance/data-files/benchmarks/.idea/modules.xml delete mode 100644 pyperformance/data-files/benchmarks/.idea/vcs.xml diff --git a/pyperformance/data-files/benchmarks/.idea/.gitignore b/pyperformance/data-files/benchmarks/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/pyperformance/data-files/benchmarks/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/pyperformance/data-files/benchmarks/.idea/benchmarks.iml b/pyperformance/data-files/benchmarks/.idea/benchmarks.iml deleted file mode 100644 index 8b8c3954..00000000 --- a/pyperformance/data-files/benchmarks/.idea/benchmarks.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml b/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da..00000000 --- a/pyperformance/data-files/benchmarks/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/misc.xml b/pyperformance/data-files/benchmarks/.idea/misc.xml deleted file mode 100644 index d1e22ecb..00000000 --- a/pyperformance/data-files/benchmarks/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/modules.xml b/pyperformance/data-files/benchmarks/.idea/modules.xml deleted file mode 100644 index 799c48d3..00000000 --- a/pyperformance/data-files/benchmarks/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/pyperformance/data-files/benchmarks/.idea/vcs.xml b/pyperformance/data-files/benchmarks/.idea/vcs.xml deleted file mode 100644 index 6c0b8635..00000000 --- a/pyperformance/data-files/benchmarks/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From abed425b9073f9b83fa5ed444737a49d6ee2f375 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 28 Apr 2022 16:47:16 +0300 Subject: [PATCH 4/4] updated test_noperf.py veriants + add option -b * fix mispellings --- .../benchmarks/bm_2to3/test_noperf.py | 7 ++++++- .../benchmarks/bm_chameleon/test_noperf.py | 7 ++++++- .../benchmarks/bm_chaos/test_noperf.py | 7 ++++++- .../benchmarks/bm_crypto_pyaes/test_noperf.py | 7 ++++++- .../benchmarks/bm_deltablue/test_noperf.py | 7 ++++++- .../bm_django_template/test_noperf.py | 7 ++++++- .../benchmarks/bm_dulwich_log/test_noperf.py | 7 ++++++- .../benchmarks/bm_fannkuch/test_noperf.py | 7 ++++++- .../benchmarks/bm_float/test_noperf.py | 7 ++++++- .../benchmarks/bm_genshi/test_noperf.py | 7 ++++++- .../benchmarks/bm_go/test_noperf.py | 7 ++++++- .../benchmarks/bm_hexiom/test_noperf.py | 7 ++++++- .../benchmarks/bm_hg_startup/test_noperf.py | 9 ++++++-- .../benchmarks/bm_html5lib/test_noperf.py | 7 ++++++- .../benchmarks/bm_json_dumps/test_noperf.py | 7 ++++++- .../benchmarks/bm_json_loads/test_noperf.py | 7 ++++++- .../benchmarks/bm_logging/test_noperf.py | 7 ++++++- .../benchmarks/bm_mako/test_noperf.py | 7 ++++++- .../benchmarks/bm_mdp/test_noperf.py | 7 ++++++- .../bm_meteor_contest/test_noperf.py | 7 ++++++- .../benchmarks/bm_nbody/test_noperf.py | 7 ++++++- .../benchmarks/bm_nqueens/test_noperf.py | 7 ++++++- .../benchmarks/bm_pathlib/test_noperf.py | 7 ++++++- .../benchmarks/bm_pickle/test_noperf.py | 21 +++++++------------ .../benchmarks/bm_pidigits/test_noperf.py | 7 ++++++- .../benchmarks/bm_pyflate/test_noperf.py | 7 ++++++- .../bm_python_startup/test_noperf.py | 8 ++++++- .../benchmarks/bm_raytrace/test_noperf.py | 7 ++++++- .../bm_regex_compile/test_noperf.py | 7 ++++++- .../benchmarks/bm_regex_dna/test_noperf.py | 7 ++++++- .../benchmarks/bm_regex_effbot/test_noperf.py | 7 ++++++- .../benchmarks/bm_regex_v8/test_noperf.py | 7 ++++++- .../benchmarks/bm_richards/test_noperf.py | 7 ++++++- .../benchmarks/bm_scimark/test_noperf.py | 7 ++++++- .../bm_spectral_norm/test_noperf.py | 7 ++++++- .../bm_sqlalchemy_declarative/test_noperf.py | 7 ++++++- .../bm_sqlalchemy_imperative/test_noperf.py | 7 ++++++- .../benchmarks/bm_sqlite_synth/test_noperf.py | 7 ++++++- .../benchmarks/bm_sympy/test_noperf.py | 7 ++++++- .../benchmarks/bm_telco/test_noperf.py | 7 ++++++- .../benchmarks/bm_tornado_http/test_noperf.py | 7 ++++++- .../bm_unpack_sequence/test_noperf.py | 8 ++++++- .../benchmarks/bm_xml_etree/test_noperf.py | 9 ++++++-- 43 files changed, 264 insertions(+), 57 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py b/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py index 51613823..dec911b5 100644 --- a/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_2to3/test_noperf.py @@ -17,6 +17,11 @@ type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -29,7 +34,7 @@ subprocess.run(command, capture_output=True) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py b/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py index e69767db..1b74bfac 100644 --- a/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_chameleon/test_noperf.py @@ -29,6 +29,11 @@ type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -43,7 +48,7 @@ func() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_chaos/test_noperf.py b/pyperformance/data-files/benchmarks/bm_chaos/test_noperf.py index cb87bc82..008c7c9c 100644 --- a/pyperformance/data-files/benchmarks/bm_chaos/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_chaos/test_noperf.py @@ -285,6 +285,11 @@ def add_cmdline_args(cmd, args): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--thickness", type=float, default=DEFAULT_THICKNESS, help="Thickness (default: %s)" % DEFAULT_THICKNESS) @@ -312,7 +317,7 @@ def add_cmdline_args(cmd, args): run(args) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py b/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py index 01dcad3d..5cf38131 100644 --- a/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_crypto_pyaes/test_noperf.py @@ -43,6 +43,11 @@ def bench_pyaes(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -51,7 +56,7 @@ def bench_pyaes(): bench_pyaes() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py b/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py index 90e1dc78..f48ad879 100644 --- a/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_deltablue/test_noperf.py @@ -641,6 +641,11 @@ def delta_blue(n): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -650,7 +655,7 @@ def delta_blue(n): delta_blue(n) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py b/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py index c0fdacb2..f3cece6c 100644 --- a/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_django_template/test_noperf.py @@ -42,6 +42,11 @@ def prepare_cmd(runner, cmd): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--table-size", type=int, default=DEFAULT_SIZE, help="Size of the HTML table, height and width " @@ -58,7 +63,7 @@ def prepare_cmd(runner, cmd): bench_django_template(args.table_size) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py b/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py index 5c7e857d..f64fd122 100644 --- a/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_dulwich_log/test_noperf.py @@ -26,6 +26,11 @@ def iter_all_commits(repo): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -39,7 +44,7 @@ def iter_all_commits(repo): profiler.disable() profiler.dump_stats("test.prof") - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py b/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py index 10193bc8..0a5095fc 100644 --- a/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_fannkuch/test_noperf.py @@ -65,6 +65,11 @@ def main(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -74,7 +79,7 @@ def main(): fannkuch(arg) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_float/test_noperf.py b/pyperformance/data-files/benchmarks/bm_float/test_noperf.py index 914ed639..af667601 100644 --- a/pyperformance/data-files/benchmarks/bm_float/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_float/test_noperf.py @@ -63,6 +63,11 @@ def benchmark(n): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -72,7 +77,7 @@ def benchmark(n): benchmark(points) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py b/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py index 91249f8b..51448a53 100644 --- a/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_genshi/test_noperf.py @@ -50,6 +50,11 @@ def bench_genshi(tmpl_cls, tmpl_str): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -69,7 +74,7 @@ def bench_genshi(tmpl_cls, tmpl_str): bench_genshi(tmpl_cls, tmpl_str) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_go/test_noperf.py b/pyperformance/data-files/benchmarks/bm_go/test_noperf.py index b40fd2e7..22afa647 100644 --- a/pyperformance/data-files/benchmarks/bm_go/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_go/test_noperf.py @@ -462,6 +462,11 @@ def versus_cpu(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -469,7 +474,7 @@ def versus_cpu(): versus_cpu() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py b/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py index ead97374..88b3fc60 100644 --- a/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_hexiom/test_noperf.py @@ -651,6 +651,11 @@ def run(level): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--level", type=int, choices=sorted(LEVELS), default=DEFAULT_LEVEL, @@ -665,7 +670,7 @@ def run(level): run(args.level) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py b/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py index f73852eb..0ad23239 100644 --- a/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_hg_startup/test_noperf.py @@ -38,6 +38,11 @@ def get_hg_version(hg_bin): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -47,10 +52,10 @@ def get_hg_version(hg_bin): get_hg_version(hg_bin) command = [sys.executable, hg_bin, "help"] - subprocces.run(command) + subprocess.run(command) profiler.disable() - s = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py b/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py index 8b025da9..785cf3a1 100644 --- a/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_html5lib/test_noperf.py @@ -30,6 +30,11 @@ def bench_html5lib(html_file): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -44,7 +49,7 @@ def bench_html5lib(html_file): bench_html5lib(html_file) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py b/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py index 0f07d59d..0372b03d 100644 --- a/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_json_dumps/test_noperf.py @@ -38,6 +38,11 @@ def add_cmdline_args(cmd, args): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--cases", help="Comma separated list of cases. Available cases: %s. By default, run all cases." % ', '.join(CASES)) @@ -66,7 +71,7 @@ def add_cmdline_args(cmd, args): bench_json_dumps(data) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py b/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py index c5a2226f..59c2fd52 100644 --- a/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_json_loads/test_noperf.py @@ -105,6 +105,11 @@ def bench_json_loads(objs): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -117,7 +122,7 @@ def bench_json_loads(objs): bench_json_loads(objs) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py b/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py index 8fd86d19..8fe55704 100644 --- a/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_logging/test_noperf.py @@ -129,6 +129,11 @@ def bench_formatted_output(logger, stream): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("benchmark", nargs='?', choices=sorted(BENCHMARKS)) @@ -158,7 +163,7 @@ def bench_formatted_output(logger, stream): bench_formatted_output(logger, stream) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(options.sorting) ps.print_stats(options.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py b/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py index b5ac2fc1..34f011d4 100644 --- a/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_mako/test_noperf.py @@ -142,6 +142,11 @@ def bench_mako(table_size, nparagraph, img_count): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -151,7 +156,7 @@ def bench_mako(table_size, nparagraph, img_count): nparagraph = 50 img_count = 50 bench_mako(table_size, nparagraph, img_count) - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py b/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py index 083a1146..f61c2bb9 100644 --- a/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_mdp/test_noperf.py @@ -266,6 +266,11 @@ def bench_mdp(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -273,7 +278,7 @@ def bench_mdp(): bench_mdp() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py b/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py index 865d3ccd..cd9e6fa3 100644 --- a/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_meteor_contest/test_noperf.py @@ -211,6 +211,11 @@ def bench_meteor_contest(board, pieces, solve_arg, fps, se_nh): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -223,7 +228,7 @@ def bench_meteor_contest(board, pieces, solve_arg, fps, se_nh): solve_arg = SOLVE_ARG bench_meteor_contest(board, pieces, solve_arg, fps, se_nh) - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py b/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py index 1196db50..45507876 100644 --- a/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_nbody/test_noperf.py @@ -142,6 +142,11 @@ def bench_nbody(reference, iterations): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--iterations", type=int, default=DEFAULT_ITERATIONS, help="Number of nbody advance() iterations " @@ -158,7 +163,7 @@ def bench_nbody(reference, iterations): bench_nbody(args.reference, args.iterations) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py b/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py index e7b8bc39..bf2cd5a8 100644 --- a/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_nqueens/test_noperf.py @@ -65,6 +65,11 @@ def bench_n_queens(queen_count): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -73,7 +78,7 @@ def bench_n_queens(queen_count): queen_count = 8 bench_n_queens(queen_count) - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py index a97b6e8d..e016e17c 100644 --- a/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_pathlib/test_noperf.py @@ -68,6 +68,11 @@ def bench_pathlib(tmp_path): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -79,7 +84,7 @@ def bench_pathlib(tmp_path): finally: shutil.rmtree(tmp_path) - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py index f1d7e05f..91e4ee43 100644 --- a/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_pickle/test_noperf.py @@ -254,6 +254,11 @@ def is_accelerated_module(module): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--pure-python", action="store_true", help="Use the C version of pickle.") @@ -266,17 +271,7 @@ def is_accelerated_module(module): options = parser.parse_args() - parser = ArgumentParser() - parser.add_argument("-b", "--builtins", - action="store_false", - help="option for cProfile.Profile() class") - parser.add_argument("-a", "--amount", - type=int, - default=20, - help="number of cumbersome functions") - args = parser.parse_args() - - profiler = Profile(builtins=args.builtins) + profiler = Profile(builtins=options.builtins) profiler.enable() if not (options.pure_python or IS_PYPY): @@ -298,8 +293,8 @@ def is_accelerated_module(module): benchmark(inner_loops, pickle, options) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(options.sorting) - ps.print_stats(args.amount) + ps.print_stats(options.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py index 05b804c4..ad504ee0 100644 --- a/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_pidigits/test_noperf.py @@ -67,6 +67,11 @@ def add_cmdline_args(cmd, args): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--digits", type=int, default=DEFAULT_DIGITS, @@ -79,7 +84,7 @@ def add_cmdline_args(cmd, args): calc_ndigits(args.digits) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py b/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py index 606e6f87..991fc669 100755 --- a/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_pyflate/test_noperf.py @@ -661,6 +661,11 @@ def bench_pyflake(filename): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -670,7 +675,7 @@ def bench_pyflake(filename): "data", "interpreter.tar.bz2") bench_pyflake(filename) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py b/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py index fa78532f..922e9a6f 100644 --- a/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_python_startup/test_noperf.py @@ -18,12 +18,18 @@ type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--no-site", action="store_true") parser.add_argument("--exit", action="store_true") args = parser.parse_args() + name = 'python_startup' profiler = Profile(builtins=args.builtins) profiler.enable() @@ -44,7 +50,7 @@ subprocess.run(command) profiler.disable() profiler.dump_stats("test.prof") - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py b/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py index 7fc147b0..f9789fb0 100644 --- a/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_raytrace/test_noperf.py @@ -385,6 +385,11 @@ def bench_raytrace( width, height, filename): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--width", type=int, default=DEFAULT_WIDTH, @@ -404,7 +409,7 @@ def bench_raytrace( width, height, filename): bench_raytrace(args.width, args.height, args.filename) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py index 73bf8ddc..19bb1704 100644 --- a/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_regex_compile/test_noperf.py @@ -65,6 +65,11 @@ def bench_regex_compile(regexes): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -73,7 +78,7 @@ def bench_regex_compile(regexes): regexes = capture_regexes() bench_regex_compile(regexes) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py index 742a6e40..b6f2afe1 100644 --- a/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_regex_dna/test_noperf.py @@ -203,6 +203,11 @@ def bench_regex_dna(seq, expected_res): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--fasta-length", type=int, default=DEFAULT_INIT_LEN, @@ -233,7 +238,7 @@ def bench_regex_dna(seq, expected_res): bench_regex_dna(seq, expected_res) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py index 58aa5768..d8ba1434 100644 --- a/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_regex_effbot/test_noperf.py @@ -163,6 +163,11 @@ def bench_regex_effbot(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("-B", "--force_bytes", action="store_true", help="test bytes regexps") @@ -177,7 +182,7 @@ def bench_regex_effbot(): bench_regex_effbot() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py b/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py index 80413fc9..dd0384af 100644 --- a/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_regex_v8/test_noperf.py @@ -1792,6 +1792,11 @@ def bench_regex_v8(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=False) @@ -1799,7 +1804,7 @@ def bench_regex_v8(): bench_regex_v8() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py b/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py index 5e58dbf1..afc03d6d 100644 --- a/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_richards/test_noperf.py @@ -426,6 +426,11 @@ def run(self, iterations): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -434,7 +439,7 @@ def run(self, iterations): richard = Richards() richard.run(1) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py b/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py index 6ac624f8..97ebc36b 100644 --- a/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_scimark/test_noperf.py @@ -396,6 +396,11 @@ def bench_FFT(N, cycles): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("benchmark", nargs='?', choices=sorted(BENCHMARKS)) @@ -417,7 +422,7 @@ def bench_FFT(N, cycles): profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py b/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py index a8d39e8e..c4518e50 100644 --- a/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_spectral_norm/test_noperf.py @@ -71,13 +71,18 @@ def bench_spectral_norm(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) profiler.enable() bench_spectral_norm() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py index e986e99a..0bfb1ef6 100644 --- a/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_sqlalchemy_declarative/test_noperf.py @@ -89,6 +89,11 @@ def bench_sqlalchemy(npeople): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--rows", type=int, default=100, @@ -101,7 +106,7 @@ def bench_sqlalchemy(npeople): bench_sqlalchemy(args.rows) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py index 5fb2b54e..726037b9 100644 --- a/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_sqlalchemy_imperative/test_noperf.py @@ -78,6 +78,11 @@ def bench_sqlalchemy(npeople): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--rows", type=int, default=100, @@ -90,7 +95,7 @@ def bench_sqlalchemy(npeople): bench_sqlalchemy(args.rows) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py index 77ebc677..ebb9c44d 100644 --- a/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_sqlite_synth/test_noperf.py @@ -56,13 +56,18 @@ def bench_sqlite(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) profiler.enable() bench_sqlite() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py b/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py index 6bb6391e..5dd247fe 100644 --- a/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_sympy/test_noperf.py @@ -47,6 +47,11 @@ def bench_sympy(funnc): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("benchmark", nargs='?', choices=BENCHMARKS) args = parser.parse_args() @@ -69,7 +74,7 @@ def bench_sympy(funnc): profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py b/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py index f12cb456..060cbb89 100644 --- a/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_telco/test_noperf.py @@ -86,6 +86,11 @@ def bench_telco(filename): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -94,7 +99,7 @@ def bench_telco(filename): filename = rel_path("data", "telco-bench.b") bench_telco(filename) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py b/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py index c8550277..9ccd426c 100644 --- a/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_tornado_http/test_noperf.py @@ -98,6 +98,11 @@ def run_client(): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") args = parser.parse_args() profiler = Profile(builtins=args.builtins) @@ -109,7 +114,7 @@ def run_client(): bench_tornado() profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py b/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py index feaa5d72..7f353ced 100644 --- a/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_unpack_sequence/test_noperf.py @@ -443,11 +443,17 @@ def bench_all(loops): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("benchmark", nargs="?", choices=sorted(benchmarks)) options = parser.parse_args() + name = 'unpack_sequence' profiler = Profile(builtins=options.builtins) profiler.enable() @@ -458,7 +464,7 @@ def bench_all(loops): func = bench_all func(loops=400) - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(options.sorting) ps.print_stats(options.amount) ps.dump_stats("test.prof") diff --git a/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py b/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py index 52b30e62..e89968b5 100644 --- a/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py +++ b/pyperformance/data-files/benchmarks/bm_xml_etree/test_noperf.py @@ -218,6 +218,11 @@ def bench_etree(etree, bench_func): type=int, default=20, help="number of cumbersome functions") + parser.add_argument("-s", "--sorting", + type=str, + choices=["tottime", "cumtime"], + default="tottime", + help="profile entries sotring order") parser.add_argument("--etree-module", default=None, metavar="FQMN", @@ -280,7 +285,7 @@ def import_module(module_name): module += ' (pure Python)' if args.benchmark: - benchmarks = (options.benchmark,) + benchmarks = (args.benchmark,) else: benchmarks = BENCHMARKS @@ -289,7 +294,7 @@ def import_module(module_name): bench_func = globals()['bench_%s' % bench] bench_etree(etree_module, bench_func) profiler.disable() - ps = Stats(profiler).sort_stats(SortKey.TIME) + ps = Stats(profiler).sort_stats(args.sorting) ps.print_stats(args.amount) ps.dump_stats("test.prof")