Include module for desktop build
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from pyutil import randutil
|
||||
import random
|
||||
from decimal import Decimal
|
||||
|
||||
l = []
|
||||
s = None
|
||||
|
||||
def data_strings(N):
|
||||
assert isinstance(N, int), (N, type(N))
|
||||
del l[:]
|
||||
for i in range(N):
|
||||
l.append(repr(randutil.insecurerandstr(4)))
|
||||
global s
|
||||
s = json.dumps(l)
|
||||
|
||||
def data_Decimals(N):
|
||||
del l[:]
|
||||
for i in range(N):
|
||||
l.append(Decimal(str(random.randrange(0, 1000000000)))/random.randrange(1, 1000000000))
|
||||
global s
|
||||
s = jsonutil.dumps(l)
|
||||
|
||||
def data_floats(N):
|
||||
del l[:]
|
||||
for i in range(N):
|
||||
l.append(float(random.randrange(0, 1000000000))/random.randrange(1, 1000000000))
|
||||
global s
|
||||
s = json.dumps(l)
|
||||
|
||||
import json
|
||||
from pyutil import jsonutil
|
||||
|
||||
def je(N):
|
||||
return json.dumps(l)
|
||||
|
||||
def ue(N):
|
||||
return jsonutil.dumps(l)
|
||||
|
||||
def jd(N):
|
||||
return json.loads(s)
|
||||
|
||||
def ud(N):
|
||||
return jsonutil.loads(s)
|
||||
|
||||
from pyutil import benchutil
|
||||
|
||||
for i in (data_strings, data_floats, data_Decimals):
|
||||
for e in (ud, ue, jd, je):
|
||||
# for e in (ue,):
|
||||
print "i: %s, e: %s" % (i, e,)
|
||||
try:
|
||||
benchutil.bench(e, initfunc=i, TOPXP=5, profile=False)
|
||||
except TypeError, e:
|
||||
print "skipping due to %s" % (e,)
|
||||
benchutil.print_bench_footer()
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2002-2010 Zooko Wilcox-O'Hearn
|
||||
# This file is part of pyutil; see README.rst for licensing terms.
|
||||
|
||||
import hmac, sys, random
|
||||
|
||||
from pyutil.assertutil import _assert
|
||||
from pyutil.xor import xor
|
||||
from pyutil import benchfunc
|
||||
from pyutil import randutil
|
||||
|
||||
SFUNCS = [hmac._strxor, xor.py_xor,]
|
||||
|
||||
SFNAMES = ["hmac", "pyutil py",]
|
||||
inputs = {}
|
||||
|
||||
def _help_init_string(N):
|
||||
global inputs
|
||||
if not inputs.has_key(N):
|
||||
inputs[N] = [randutil.insecurerandstr(N), randutil.insecurerandstr(N),]
|
||||
|
||||
def _help_make_bench_xor(f):
|
||||
def g(n):
|
||||
assert inputs.has_key(n)
|
||||
_assert(isinstance(inputs[n][0], str), "Required to be a string.", inputs[n][0])
|
||||
assert len(inputs[n][0]) == n
|
||||
_assert(isinstance(inputs[n][1], str), "Required to be a string.", inputs[n][1])
|
||||
assert len(inputs[n][1]) == n
|
||||
for SF in SFUNCS:
|
||||
assert f(inputs[n][0], inputs[n][1]) == SF(inputs[n][0], inputs[n][1])
|
||||
|
||||
return f(inputs[n][0], inputs[n][1])
|
||||
return g
|
||||
|
||||
def bench(SETSIZES=[2**x for x in range(0, 22, 3)]):
|
||||
random.seed(0)
|
||||
if len(SFUNCS) <= 1: print ""
|
||||
maxnamel = max(map(len, SFNAMES))
|
||||
for SETSIZE in SETSIZES:
|
||||
seed = random.random()
|
||||
# print "seed: ", seed
|
||||
random.seed(seed)
|
||||
i = 0
|
||||
if len(SFUNCS) > 1: print ""
|
||||
for FUNC in SFUNCS:
|
||||
funcname = SFNAMES[i] + " " * (maxnamel - len(SFNAMES[i]))
|
||||
print "%s" % funcname,
|
||||
sys.stdout.flush()
|
||||
benchfunc.rep_bench(_help_make_bench_xor(FUNC), SETSIZE, initfunc=_help_init_string, MAXREPS=2**9, MAXTIME=30)
|
||||
i = i + 1
|
||||
|
||||
bench()
|
||||
Reference in New Issue
Block a user