Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use smaller sizes to stress obmalloc
  • Loading branch information
tiran committed Feb 8, 2022
commit 633ece4568ae2b04c281d683c2bdbf0dbb64c1af
25 changes: 21 additions & 4 deletions pyperformance/data-files/benchmarks/bm_alloc/run_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@
"""
Allocate blocks of memory with bytearray

This benchmark stresses memory allocator
This benchmark stresses memory allocator. Default sizes are <=
obmalloc small request threshold.
Comment thread
tiran marked this conversation as resolved.
Outdated
"""

import pyperf
import sys

import pyperf

ONE_MB = 1024 * 1024
# see Objects/obmalloc.c
SMALL_REQUEST_THRESHOLD = 512
APPEND_SIZE = 10
SIZEOF_BYTEARRAY = sys.getsizeof(bytearray())

DEFAULT_SIZES = [32, 128, 512, 8192, ONE_MB, 8 * ONE_MB]
REPEAT_ALLOCS = 100

DEFAULT_SIZES = [
4,
8,
16,
32,
64,
128,
256,
# keep below obmalloc threshold
SMALL_REQUEST_THRESHOLD - SIZEOF_BYTEARRAY - APPEND_SIZE,
]


def allocate(repeat, sizes, alloc_func=bytearray):
append = alloc_func(APPEND_SIZE)
for size in sizes:
append = alloc_func(size)
for i in range(repeat):
Expand Down