Skip to content

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Sep 5, 2024

Benchmark:

import pyperf
runner = pyperf.Runner()

setup="""
import copy

a={'list': [1,2,3,43], 't': (1,2,3), 'str': 'hello', 'subdict': {'a': True}}

from dataclasses import dataclass

lst = [1, 's']

@dataclass
class A:
    a : int
    
dc = A(123)
list_dc = [A(1), A(2), A(3), A(4)]
"""

runner.timeit(name="deepcopy dict", stmt=f"b=copy.deepcopy(a)", setup=setup)
runner.timeit(name="deepcopy dataclass", stmt=f"b=copy.deepcopy(dc)", setup=setup)
runner.timeit(name="deepcopy small list", stmt=f"b=copy.deepcopy(lst)", setup=setup)
runner.timeit(name="deepcopy list dataclasses", stmt=f"b=copy.deepcopy(list_dc)", setup=setup) 

Results:

deepcopy dict: Mean +- std dev: [main] 11.3 us +- 0.9 us -> [pr] 10.2 us +- 0.1 us: 1.11x faster
deepcopy dataclass: Mean +- std dev: [main] 8.62 us +- 0.29 us -> [pr] 7.74 us +- 0.30 us: 1.11x faster
deepcopy small list: Mean +- std dev: [main] 2.48 us +- 0.10 us -> [pr] 2.20 us +- 0.31 us: 1.13x faster
deepcopy list dataclasses: Mean +- std dev: [main] 34.1 us +- 1.3 us -> [pr] 32.9 us +- 1.0 us: 1.03x faster

Geometric mean: 1.10x faster

See the corresponding issue for further details.

@eendebakpt
Copy link
Contributor Author

Updated benchmarks (new machine, but roughly the same)

deepcopy int: Mean +- std dev: [main] 47.1 ns +- 0.3 ns -> [pr] 43.2 ns +- 0.2 ns: 1.09x faster
deepcopy dict: Mean +- std dev: [main] 2.58 us +- 0.02 us -> [pr] 2.38 us +- 0.02 us: 1.08x faster
deepcopy dataclass: Mean +- std dev: [main] 2.28 us +- 0.02 us -> [pr] 2.11 us +- 0.02 us: 1.08x faster
deepcopy small list: Mean +- std dev: [main] 615 ns +- 2 ns -> [pr] 494 ns +- 3 ns: 1.25x faster
deepcopy list of dataclasses: Mean +- std dev: [main] 9.19 us +- 0.09 us -> [pr] 8.89 us +- 0.07 us: 1.03x faster

Geometric mean: 1.10x faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant