Skip to content

Commit

Permalink
Fix benchmarks to use pyperf
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip authored and jeffwidman committed Feb 5, 2020
1 parent d54aaf6 commit 385f603
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions benchmarks/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `record_batch_*` benchmarks in this section are written using
``perf`` library, created by Viktor Stinner. For more information on how to get
reliable results of test runs please consult
https://perf.readthedocs.io/en/latest/run_benchmark.html.
``pyperf`` library, created by Victor Stinner. For more information on
how to get reliable results of test runs please consult
https://pyperf.readthedocs.io/en/latest/run_benchmark.html.
8 changes: 4 additions & 4 deletions benchmarks/record_batch_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import random

import perf
import pyperf

from kafka.record.memory_records import MemoryRecordsBuilder

Expand Down Expand Up @@ -52,7 +52,7 @@ def func(loops, magic):
results = []

# Main benchmark code.
t0 = perf.perf_counter()
t0 = pyperf.perf_counter()
for _ in range(loops):
batch = MemoryRecordsBuilder(
magic, batch_size=DEFAULT_BATCH_SIZE, compression_type=0)
Expand All @@ -64,14 +64,14 @@ def func(loops, magic):
batch.close()
results.append(batch.buffer())

res = perf.perf_counter() - t0
res = pyperf.perf_counter() - t0

finalize(results)

return res


runner = perf.Runner()
runner = pyperf.Runner()
runner.bench_time_func('batch_append_v0', func, 0)
runner.bench_time_func('batch_append_v1', func, 1)
runner.bench_time_func('batch_append_v2', func, 2)
8 changes: 4 additions & 4 deletions benchmarks/record_batch_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import random

import perf
import pyperf

from kafka.record.memory_records import MemoryRecords, MemoryRecordsBuilder

Expand Down Expand Up @@ -61,7 +61,7 @@ def func(loops, magic):

# Main benchmark code.
batch_data = next(precomputed_samples)
t0 = perf.perf_counter()
t0 = pyperf.perf_counter()
for _ in range(loops):
records = MemoryRecords(batch_data)
while records.has_next():
Expand All @@ -70,13 +70,13 @@ def func(loops, magic):
for record in batch:
results.append(record.value)

res = perf.perf_counter() - t0
res = pyperf.perf_counter() - t0
finalize(results)

return res


runner = perf.Runner()
runner = pyperf.Runner()
runner.bench_time_func('batch_read_v0', func, 0)
runner.bench_time_func('batch_read_v1', func, 1)
runner.bench_time_func('batch_read_v2', func, 2)
4 changes: 2 additions & 2 deletions benchmarks/varint_speed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
import perf
import pyperf
from kafka.vendor import six


Expand Down Expand Up @@ -398,7 +398,7 @@ def decode_varint_3(buffer, pos=0):
# import dis
# dis.dis(decode_varint_3)

runner = perf.Runner()
runner = pyperf.Runner()
# Encode algorithms returning a bytes result
for bench_func in [
encode_varint_1,
Expand Down

0 comments on commit 385f603

Please sign in to comment.