Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions doc/benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ See `pyaes <https://github.com/ricmoo/pyaes>`_: A pure-Python implementation of
the AES block cipher algorithm and the common modes of operation (CBC, CFB,
CTR, ECB and OFB).

deepcopy
--------

Benchmark the Python `copy.deepcopy` method. The `deepcopy` method is
performed on a nested dictionary and a dataclass.

deltablue
---------
Expand Down
1 change: 1 addition & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name metafile
chameleon <local>
chaos <local>
crypto_pyaes <local>
deepcopy <local>
deltablue <local>
django_template <local>
dulwich_log <local>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "pyperformance_bm_deepcopy"
requires-python = ">=3.8"
dependencies = ["pyperf"]
urls = {repository = "https://github.com/python/pyperformance"}
dynamic = ["version"]

[tool.pyperformance]
name = "deepcopy"
42 changes: 42 additions & 0 deletions pyperformance/data-files/benchmarks/bm_deepcopy/run_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Benchmark to measure performance of the python builtin method copy.deepcopy

Performance is tested on a nested dictionary and a dataclass

Author: Pieter Eendebak

"""
import copy
import pyperf
from dataclasses import dataclass

@dataclass
class A:
string : str
lst : list
boolean : bool


def benchmark(n):
a={'list': [1,2,3,43], 't': (1,2,3), 'str': 'hello', 'subdict': {'a': True}}
Comment thread
eendebakpt marked this conversation as resolved.
Outdated
dc=A('hello', [1,2,3], True)
Comment thread
eendebakpt marked this conversation as resolved.
Outdated

for ii in range(n):

for jj in range(60):
_ = copy.deepcopy(a)

for s in ['red', 'blue', 'green']:
dc.string = s
for ii in range(10):
dc.lst[0] = ii
Comment thread
eendebakpt marked this conversation as resolved.
Outdated
for b in [True, False]:
dc.boolean=b
_ = copy.deepcopy(dc)
Comment thread
eendebakpt marked this conversation as resolved.
Outdated


if __name__ == "__main__":
runner = pyperf.Runner()
runner.metadata['description'] = "deepcopy benchmark"

runner.bench_func('deepcopy', benchmark, 200)
Comment thread
eendebakpt marked this conversation as resolved.
Outdated