Example #1
0
def main(argv=None):
    import os
    import sys
    if argv is None:
        argv = sys.argv[1:]

    env_options = [
        '--inherit-environ',
        ','.join([k for k in os.environ
                  if k.startswith(('GEVENT',
                                   'PYTHON',
                                   'ZS', # experimental zodbshootout config
                                   'RS', # relstorage config
                                   'COVERAGE'))])]
    # This is a default, so put it early
    argv[0:0] = env_options

    def worker_cmd(cmd, args):
        cmd.extend(args.benchmark)

    runner = Runner(add_cmdline_args=worker_cmd)
    runner.argparser.add_argument('benchmark',
                                  nargs='*',
                                  default='all',
                                  choices=all() + ['all'])

    def spawn_time(loops, func, options):
        options.loops = loops
        times = func(options)
        return times.spawn_duration

    def sleep_time(loops, func, options):
        options.loops = loops
        times = func(options)
        return times.sleep_duration

    def join_time(loops, func, options):
        options.loops = loops
        times = func(options)
        return times.join_duration

    args = runner.parse_args(argv)

    if 'all' in args.benchmark or args.benchmark == 'all':
        args.benchmark = ['all']
        names = all()
    else:
        names = args.benchmark

    names = sorted(set(names))

    for name in names:
        runner.bench_time_func(name + ' spawn',
                               spawn_time,
                               globals()['bench_' + name],
                               Options(sleep=False, join=False),
                               inner_loops=N)

        if name != 'none':
            runner.bench_time_func(name + ' sleep',
                                   sleep_time,
                                   globals()['bench_' + name],
                                   Options(sleep=True, join=False),
                                   inner_loops=N)

    if 'geventpool' in names:
        runner.bench_time_func('geventpool join',
                               join_time,
                               bench_geventpool,
                               Options(sleep=True, join=True),
                               inner_loops=N)

    for name in names:
        runner.bench_time_func(name + ' spawn kwarg',
                               spawn_time,
                               globals()['bench_' + name],
                               Options(sleep=False, join=False, foo=1, bar='hello'),
                               inner_loops=N)
#!/usr/bin/env python
"""
A performance benchmark using the example from issue #232.

See https://github.com/Julian/jsonschema/pull/232.
"""
from twisted.python.filepath import FilePath
from pyperf import Runner
from pyrsistent import m

from jsonschema.tests._suite import Version
import jsonschema


issue232 = Version(
    path=FilePath(__file__).sibling("issue232"),
    remotes=m(),
    name="issue232",
)


if __name__ == "__main__":
    issue232.benchmark(
        runner=Runner(),
        Validator=jsonschema.Draft4Validator,
    )
#!/usr/bin/env python
"""
A performance benchmark using the official test suite.

This benchmarks jsonschema using every valid example in the
JSON-Schema-Test-Suite. It will take some time to complete.
"""
from pyperf import Runner

from jsonschema.tests._suite import Suite

if __name__ == "__main__":
    Suite().benchmark(runner=Runner())
Example #4
0
from boto3.dynamodb.types import TypeDeserializer
from pyperf import Runner

from utils import generate_data


data = generate_data()


def deserialize_aiodynamo():
    result = [
        {k: TypeDeserializer().deserialize(v) for k, v in item.items()} for item in data
    ]


Runner().bench_func("deserialize", deserialize_aiodynamo)
import asyncio

from aiohttp import ClientSession
from boto3.dynamodb.conditions import Key
from pyperf import Runner

from aiodynamo.client import Client
from aiodynamo.credentials import Credentials
from aiodynamo.http.aiohttp import AIOHTTP
from utils import TABLE_NAME, KEY_FIELD, KEY_VALUE, REGION_NAME


async def inner():
    async with ClientSession() as session:
        client = Client(AIOHTTP(session), Credentials.auto(), REGION_NAME)
        items = [
            item
            async for item in client.query(TABLE_NAME, Key(KEY_FIELD).eq(KEY_VALUE))
        ]


def query_aiodynamo_aiohttp():
    asyncio.run(inner())


Runner().bench_func("query", query_aiodynamo_aiohttp)
Example #6
0
from pyperf import Runner

from aiodynamo.sign import signed_dynamo_request
from data import *


def sign_aiodynamo():
    signed_dynamo_request(key=KEY,
                          payload=PAYLOAD,
                          action=ACTION,
                          region=REGION)


Runner().bench_func("sign", sign_aiodynamo)
Example #7
0
from botocore.session import get_session
from pyperf import Runner

from utils import TABLE_NAME, KEY_FIELD, KEY_VALUE, REGION_NAME


def query_botocore():
    client = get_session().create_client("dynamodb", region_name=REGION_NAME)
    items = []
    lek = None
    while True:
        if lek is None:
            kwargs = {}
        else:
            kwargs = {"ExclusiveStartKey": lek}
        response = client.query(
            TableName=TABLE_NAME,
            KeyConditionExpression="#k = :v",
            ExpressionAttributeNames={"#k": KEY_FIELD},
            ExpressionAttributeValues={":v": {"S": KEY_VALUE}},
            **kwargs
        )
        items.extend(response["Items"])
        lek = response.get("LastEvaluatedKey", None)
        if lek is None:
            break


Runner().bench_func("query", query_botocore)
#!/usr/bin/env python
"""
A performance benchmark using the example from issue #232.

See https://github.com/Julian/jsonschema/pull/232.
"""
from twisted.python.filepath import FilePath
from pyperf import Runner
from pyrsistent import m

from jsonschema.tests._suite import Version
import jsonschema


issue232 = Version(
    path=FilePath(__file__).sibling("issue232"), remotes=m(), name="issue232",
)


if __name__ == "__main__":
    issue232.benchmark(
        runner=Runner(), Validator=jsonschema.Draft4Validator,
    )
Example #9
0
import json

from botocore.awsrequest import AWSRequest
from botocore.hooks import HierarchicalEmitter
from botocore.model import ServiceId
from botocore.signers import RequestSigner
from pyperf import Runner

from data import *


def sign_botocore():
    request = AWSRequest(
        "POST",
        URL_STRING,
        data=json.dumps(PAYLOAD, separators=(",", ":")).encode("utf-8"),
    )
    emitter = HierarchicalEmitter()
    RequestSigner(
        ServiceId(SERVICE_NAME), REGION, SERVICE_NAME, "v4", CREDENTIALS, emitter
    ).sign(ACTION, request)


Runner().bench_func("sign", sign_botocore)