Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:47:49+00:00 2026-06-02T17:47:49+00:00

%python -m timeit -s import copy x = (1, 2, 3) copy.deepcopy(x) 100000 loops,

  • 0
%python -m timeit -s "import copy" "x = (1, 2, 3)" "copy.deepcopy(x)"
100000 loops, best of 3: 10.1 usec per loop

%python -m timeit -s "import copy" "x = (1, 2, 3)" "copy.copy(x)"
1000000 loops, best of 3: 0.609 usec per loop

Why is deepcopy 15 times slower than copy?

Each function has to iterate through the elements of the tuple. During that iteration, copy creates another reference to each element; deepcopy deepcopies each element.

But each element is an int, and deepcopying an int simply creates another reference to it. In other words, the two functions seem to perform precisely the same steps, the same number of times.

Here’s the verification that no new instances are created in the process:

ActivePython 3.2.1.2 (ActiveState Software Inc.) based on
Python 3.2.1 (default, Jul 18 2011, 14:31:09) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = (1,2,3)
>>> import copy
>>> y = copy.copy(x)
>>> z = copy.deepcopy(x)
>>> x is y
True
>>> x is z
True
>>> x[1] is z[1]
True
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:47:51+00:00Added an answer on June 2, 2026 at 5:47 pm

    Tuples are immutable, but they can contain mutable elements:

    >>> a = (1, 2, [])
    >>> a[2].append(1000)
    >>> a
    (1, 2, [1000])
    

    Note that the tuple doesn’t change: it’s the list the one that does; the tuple still contains the exact same list.

    deepcopy should recurse copying those mutable elements. copy just copies the references to them.

    >>> from copy import copy, deepcopy
    
    >>> a = (1, 2, [])
    >>> c = copy(a)
    >>> d = deepcopy(a)
    
    >>> a[2].append(1000)
    
    >>> c
    (1, 2, [1000])
    >>> d
    (1, 2, [])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Python Cookbook python timeit.py -simport random -sx=range(100000); random.shuffle(x) sorted(x) 10 loops, best of
python decimal comparison >>> from decimal import Decimal >>> Decimal('1.0') > 2.0 True I
I'm performing a nested loop in python that is included below. This serves as
While optimising my code I realised the following: >>> from timeit import Timer as
I'm having a hard time with the setup statement in Python's timeit.Timer(stmt, setup_stmt). I
When trying to use the Python built-in module 'timeit' as follows: timeit.Timer('print hi').timeit() it
I was playing around with Python's collection.deque and wrote the following benchmark: #!/usr/bin/python import
I'm under the impression that Python import is supposed to automatically unzip egg files
Why are mutable strings slower than immutable strings? EDIT: >>> import UserString ... def
I wrote this simple code (in python) in test.py. I try to run timeit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.