summaryrefslogtreecommitdiff
path: root/benchmark.py
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark.py')
-rw-r--r--benchmark.py53
1 files changed, 26 insertions, 27 deletions
diff --git a/benchmark.py b/benchmark.py
index 7f17813..15d956e 100644
--- a/benchmark.py
+++ b/benchmark.py
@@ -1,75 +1,74 @@
import timeit
-QS = ("amqplib.benchmark", "librabbit.benchmark")
+QS = ('amqplib.benchmark', 'librabbit.benchmark')
INIT_COMMON = """
-connection = amqp.Connection(hostname="localhost", userid="guest",
-password="guest", virtual_host="/")
+connection = amqp.Connection(hostname='localhost', userid='guest',
+password='guest', virtual_host='/')
channel = connection.channel()
-channel.exchange_declare(Q, "direct")
+channel.exchange_declare(Q, 'direct')
channel.queue_declare(Q)
channel.queue_bind(Q, Q, Q)
"""
INIT_AMQPLIB = """
from amqplib import client_0_8 as amqp
-Q = "amqplib.benchmark"
+Q = 'amqplib.benchmark'
%s
""" % INIT_COMMON
INIT_LIBRABBIT = """
import librabbitmq as amqp
-Q = "librabbit.benchmark"
+Q = 'librabbit.benchmark'
%s
""" % INIT_COMMON
PUBLISH = """
-message = amqp.Message("x" * %d)
+message = amqp.Message('x' * %d)
channel.basic_publish(message, exchange=Q, routing_key=Q)
"""
PUBLISH_LIBRABBIT = """
-connection._basic_publish(1, "x" * %d, Q, Q, {})
+connection._basic_publish(1, 'x' * %d, Q, Q, {})
"""
CONSUME = """
-method = getattr(channel, "wait", None) or connection.drain_events
+method = getattr(channel, 'wait', None) or connection.drain_events
def callback(m):
- channel.basic_ack(m.delivery_info["delivery_tag"])
+ channel.basic_ack(m.delivery_info['delivery_tag'])
channel.basic_consume(Q, callback=callback)
for i in range(%(its)d):
method()
"""
-def bench_basic_publish(iterations=10000, bytes=256):
+def bench_basic_publish(its=10000, bytes=256):
t_publish_amqplib = timeit.Timer(stmt=PUBLISH % bytes,
- setup=INIT_AMQPLIB)
+ setup=INIT_AMQPLIB)
t_publish_librabbit = timeit.Timer(stmt=PUBLISH_LIBRABBIT % bytes,
setup=INIT_LIBRABBIT)
- print("basic.publish: (%s byte messages)" % bytes)
- print(" amqplib: %.2f usec/pass" % (
- iterations * t_publish_amqplib.timeit(number=iterations)/iterations))
- print(" librabbit: %.2f usec/pass" % (
- iterations * t_publish_librabbit.timeit(number=iterations)/iterations))
+ print('basic.publish: (%s byte messages)' % bytes)
+ print(' amqplib: %.2f usec/pass' % (
+ its * t_publish_amqplib.timeit(number=its) / its))
+ print(' librabbit: %.2f usec/pass' % (
+ its * t_publish_librabbit.timeit(number=its) / its))
+
-def bench_basic_consume(iterations=10000):
- context = {"its": (iterations/2)/10}
+def bench_basic_consume(its=10000):
+ context = {'its': (its / 2) / 10}
t_consume_amqplib = timeit.Timer(stmt=CONSUME % context,
setup=INIT_AMQPLIB)
t_consume_librabbit = timeit.Timer(stmt=CONSUME % context,
setup=INIT_LIBRABBIT)
- print("basic.consume (%s msg/pass) " % context["its"])
- print(" amqplib: %.2f usec/pass" % (
- 10 * t_consume_amqplib.timeit(number=10)/10))
- print(" librabbit: %.2f usec/pass" % (
- 10 * t_consume_librabbit.timeit(number=10)/10))
+ print('basic.consume (%s msg/pass) ' % context['its'])
+ print(' amqplib: %.2f usec/pass' % (
+ 10 * t_consume_amqplib.timeit(number=10) / 10))
+ print(' librabbit: %.2f usec/pass' % (
+ 10 * t_consume_librabbit.timeit(number=10) / 10))
benchmarks = [bench_basic_publish, bench_basic_consume]
-if __name__ == "__main__":
+if __name__ == '__main__':
for benchmark in benchmarks:
benchmark(100000)
-
-