Fix formatting
This commit is contained in:
@@ -10,28 +10,58 @@ import time
|
|||||||
|
|
||||||
_this_dir = os.path.dirname(__file__)
|
_this_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-l', "--langs", help="Add languages to test, ie: -l pyproto -l pyproto_cpp", action='append', default=['pycapnp'])
|
parser.add_argument(
|
||||||
parser.add_argument("-r", "--reuse", help="If this flag is passed, re-use tests will be run", action='store_true')
|
"-l",
|
||||||
parser.add_argument("-c", "--compression", help="If this flag is passed, compression tests will be run", action='store_true')
|
"--langs",
|
||||||
parser.add_argument("-i", "--scale_iters", help="Scaling factor to multiply the default iters by", type=float, default=1.0)
|
help="Add languages to test, ie: -l pyproto -l pyproto_cpp",
|
||||||
|
action="append",
|
||||||
|
default=["pycapnp"],
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--reuse",
|
||||||
|
help="If this flag is passed, re-use tests will be run",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--compression",
|
||||||
|
help="If this flag is passed, compression tests will be run",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-i",
|
||||||
|
"--scale_iters",
|
||||||
|
help="Scaling factor to multiply the default iters by",
|
||||||
|
type=float,
|
||||||
|
default=1.0,
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def run_one(prefix, name, mode, iters, faster, compression):
|
def run_one(prefix, name, mode, iters, faster, compression):
|
||||||
res_type = prefix
|
res_type = prefix
|
||||||
reuse = 'no-reuse'
|
reuse = "no-reuse"
|
||||||
|
|
||||||
if faster:
|
if faster:
|
||||||
reuse = 'reuse'
|
reuse = "reuse"
|
||||||
res_type += '_reuse'
|
res_type += "_reuse"
|
||||||
if compression != 'none':
|
if compression != "none":
|
||||||
res_type += '_' + compression
|
res_type += "_" + compression
|
||||||
|
|
||||||
command = [os.path.join(_this_dir, prefix+"-"+name), mode, reuse, compression, str(iters)]
|
command = [
|
||||||
|
os.path.join(_this_dir, prefix + "-" + name),
|
||||||
|
mode,
|
||||||
|
reuse,
|
||||||
|
compression,
|
||||||
|
str(iters),
|
||||||
|
]
|
||||||
start = time.time()
|
start = time.time()
|
||||||
print('running: ' + ' '.join(command), file=sys.stderr)
|
print("running: " + " ".join(command), file=sys.stderr)
|
||||||
p = Popen(command, stdout=PIPE, stderr=PIPE)
|
p = Popen(command, stdout=PIPE, stderr=PIPE)
|
||||||
res = p.wait()
|
res = p.wait()
|
||||||
end = time.time()
|
end = time.time()
|
||||||
@@ -39,14 +69,19 @@ def run_one(prefix, name, mode, iters, faster, compression):
|
|||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
sys.stderr.write(' '.join(command) + ' failed to run with errors: \n' + p.stderr.read().decode(sys.stdout.encoding) + '\n')
|
sys.stderr.write(
|
||||||
|
" ".join(command)
|
||||||
|
+ " failed to run with errors: \n"
|
||||||
|
+ p.stderr.read().decode(sys.stdout.encoding)
|
||||||
|
+ "\n"
|
||||||
|
)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
data['type'] = res_type
|
data["type"] = res_type
|
||||||
data['mode'] = mode
|
data["mode"] = mode
|
||||||
data['name'] = name
|
data["name"] = name
|
||||||
data['iters'] = iters
|
data["iters"] = iters
|
||||||
data['time'] = end - start
|
data["time"] = end - start
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -55,28 +90,40 @@ def run_each(name, langs, reuse, compression, iters):
|
|||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
for lang_name in langs:
|
for lang_name in langs:
|
||||||
ret.append(run_one(lang_name, name, 'object', iters, False, 'none'))
|
ret.append(run_one(lang_name, name, "object", iters, False, "none"))
|
||||||
ret.append(run_one(lang_name, name, 'bytes', iters, False, 'none'))
|
ret.append(run_one(lang_name, name, "bytes", iters, False, "none"))
|
||||||
if reuse:
|
if reuse:
|
||||||
ret.append(run_one(lang_name, name, 'object', iters, True, 'none'))
|
ret.append(run_one(lang_name, name, "object", iters, True, "none"))
|
||||||
ret.append(run_one(lang_name, name, 'bytes', iters, True, 'none'))
|
ret.append(run_one(lang_name, name, "bytes", iters, True, "none"))
|
||||||
if compression:
|
if compression:
|
||||||
ret.append(run_one(lang_name, name, 'bytes', iters, True, 'packed'))
|
ret.append(run_one(lang_name, name, "bytes", iters, True, "packed"))
|
||||||
if compression:
|
if compression:
|
||||||
ret.append(run_one(lang_name, name, 'bytes', iters, False, 'packed'))
|
ret.append(run_one(lang_name, name, "bytes", iters, False, "packed"))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
os.environ['PATH'] += ':.'
|
os.environ["PATH"] += ":."
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
data += run_each('carsales', args.langs, args.reuse, args.compression, int(2000 * args.scale_iters))
|
data += run_each(
|
||||||
data += run_each('catrank', args.langs, args.reuse, args.compression, int(100 * args.scale_iters))
|
"carsales",
|
||||||
data += run_each('eval', args.langs, args.reuse, args.compression, int(10000 * args.scale_iters))
|
args.langs,
|
||||||
json.dump(data, sys.stdout, sort_keys=True, indent=4, separators=(',', ': '))
|
args.reuse,
|
||||||
|
args.compression,
|
||||||
|
int(2000 * args.scale_iters),
|
||||||
|
)
|
||||||
|
data += run_each(
|
||||||
|
"catrank", args.langs, args.reuse, args.compression, int(100 * args.scale_iters)
|
||||||
|
)
|
||||||
|
data += run_each(
|
||||||
|
"eval", args.langs, args.reuse, args.compression, int(10000 * args.scale_iters)
|
||||||
|
)
|
||||||
|
json.dump(data, sys.stdout, sort_keys=True, indent=4, separators=(",", ": "))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -8,46 +8,83 @@ from timeit import default_timer
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
_this_dir = os.path.dirname(__file__)
|
_this_dir = os.path.dirname(__file__)
|
||||||
sys.path.append(os.path.join(_this_dir, '..'))
|
sys.path.append(os.path.join(_this_dir, ".."))
|
||||||
from common import do_benchmark
|
from common import do_benchmark
|
||||||
|
|
||||||
|
|
||||||
def parse_args_simple():
|
def parse_args_simple():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("mode", help="Mode to use for serialization, ie. object or bytes")
|
parser.add_argument(
|
||||||
|
"mode", help="Mode to use for serialization, ie. object or bytes"
|
||||||
|
)
|
||||||
parser.add_argument("reuse", help="Currently ignored")
|
parser.add_argument("reuse", help="Currently ignored")
|
||||||
parser.add_argument("compression", help="Valid values are none or packed")
|
parser.add_argument("compression", help="Valid values are none or packed")
|
||||||
parser.add_argument("iters", help="Number of iterations to run for", type=int)
|
parser.add_argument("iters", help="Number of iterations to run for", type=int)
|
||||||
parser.add_argument("-I", "--includes", help="Directories to add to PYTHONPATH", default='/usr/local/include')
|
parser.add_argument(
|
||||||
|
"-I",
|
||||||
|
"--includes",
|
||||||
|
help="Directories to add to PYTHONPATH",
|
||||||
|
default="/usr/local/include",
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("name", help="Name of the benchmark to run, eg. carsales", nargs='?', default='carsales')
|
parser.add_argument(
|
||||||
parser.add_argument("-c", "--compression", help="Specify the compression type", default=None)
|
"name",
|
||||||
parser.add_argument("-s", "--suffix", help="Choose the protocol type.", default='pycapnp')
|
help="Name of the benchmark to run, eg. carsales",
|
||||||
parser.add_argument("-m", "--mode", help="Specify the mode", default='object')
|
nargs="?",
|
||||||
parser.add_argument("-i", "--iters", help="Specify the number of iterations manually. By default, it will be looked up in preset table", default=10, type=int)
|
default="carsales",
|
||||||
parser.add_argument("-r", "--reuse", help="If this flag is passed, objects will be re-used", action='store_true')
|
)
|
||||||
parser.add_argument("-I", "--includes", help="Directories to add to PYTHONPATH", default='/usr/local/include')
|
parser.add_argument(
|
||||||
|
"-c", "--compression", help="Specify the compression type", default=None
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-s", "--suffix", help="Choose the protocol type.", default="pycapnp"
|
||||||
|
)
|
||||||
|
parser.add_argument("-m", "--mode", help="Specify the mode", default="object")
|
||||||
|
parser.add_argument(
|
||||||
|
"-i",
|
||||||
|
"--iters",
|
||||||
|
help="Specify the number of iterations manually. By default, it will be looked up in preset table",
|
||||||
|
default=10,
|
||||||
|
type=int,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--reuse",
|
||||||
|
help="If this flag is passed, objects will be re-used",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-I",
|
||||||
|
"--includes",
|
||||||
|
help="Directories to add to PYTHONPATH",
|
||||||
|
default="/usr/local/include",
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def run_test(name, mode, reuse, compression, iters, suffix, includes):
|
def run_test(name, mode, reuse, compression, iters, suffix, includes):
|
||||||
tic = default_timer()
|
tic = default_timer()
|
||||||
|
|
||||||
name = name
|
name = name
|
||||||
sys.path.append(includes)
|
sys.path.append(includes)
|
||||||
module = import_module(name + '_' + suffix)
|
module = import_module(name + "_" + suffix)
|
||||||
benchmark = module.Benchmark(compression=compression)
|
benchmark = module.Benchmark(compression=compression)
|
||||||
|
|
||||||
do_benchmark(mode=mode, benchmark=benchmark, iters=iters, reuse=reuse)
|
do_benchmark(mode=mode, benchmark=benchmark, iters=iters, reuse=reuse)
|
||||||
toc = default_timer()
|
toc = default_timer()
|
||||||
return toc - tic
|
return toc - tic
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
run_test(**vars(args))
|
run_test(**vars(args))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
@@ -299,9 +299,11 @@ async def main(connection):
|
|||||||
|
|
||||||
print("PASS")
|
print("PASS")
|
||||||
|
|
||||||
|
|
||||||
async def cmd_main(host):
|
async def cmd_main(host):
|
||||||
host, port = host.split(":")
|
host, port = host.split(":")
|
||||||
await main(await capnp.AsyncIoStream.create_connection(host=host, port=port))
|
await main(await capnp.AsyncIoStream.create_connection(host=host, port=port))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(cmd_main(parse_args().host))
|
asyncio.run(cmd_main(parse_args().host))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import gc
|
import gc
|
||||||
import os
|
import os
|
||||||
import pytest
|
|
||||||
import socket
|
import socket
|
||||||
import sys # add examples dir to sys.path
|
import sys # add examples dir to sys.path
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user