Add a slice benchmark

This commit is contained in:
Anthony Shaw
2022-03-01 13:52:56 +11:00
parent bc04385656
commit d2460dc844
2 changed files with 21 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"python.linting.banditEnabled": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}

16
bench_slicing.py Normal file
View File

@@ -0,0 +1,16 @@
def bytes_slice():
"""Slice using normal bytes"""
word = b'A' * 1000
for i in range(1000):
n = word[0:i]
def memoryview_slice():
"""Convert to a memoryview first."""
word = memoryview(b'A' * 1000)
for i in range(1000):
n = word[0:i]
__benchmarks__ = [
(bytes_slice, memoryview_slice, "Slicing with memoryview instead of bytes"),
]