Created
October 6, 2014 22:59
-
-
Save nekoya/2a06bd929c90c3f240eb to your computer and use it in GitHub Desktop.
Python list copy benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from benchmarker import Benchmarker | |
items = ['foo', 'bar', 'baz', 'hoge'] | |
import copy | |
with Benchmarker(width=40, loop=100000) as bm: | |
for _ in bm('list'): | |
x = list(items) | |
for _ in bm('slice'): | |
x = items[:] | |
for _ in bm('copy'): | |
x = copy.copy(items) | |
for _ in bm('deep copy'): | |
x = copy.deepcopy(items) | |
""" | |
## benchmarker: release 3.0.1 (for python) | |
## python platform: darwin [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] | |
## python version: 2.7.6 | |
## python executable: /Users/nekoya/.pyenv/versions/py27/bin/python | |
## user sys total real | |
list 0.0700 0.0000 0.0700 0.0716 | |
slice 0.0400 0.0000 0.0400 0.0372 | |
copy 0.1400 0.0000 0.1400 0.1382 | |
deep copy 1.2500 0.0100 1.2600 1.2542 | |
## Ranking real | |
slice 0.0372 (100.0%) ************************* | |
list 0.0716 ( 51.9%) ************* | |
copy 0.1382 ( 26.9%) ******* | |
deep copy 1.2542 ( 3.0%) * | |
## Ratio Matrix real [01] [02] [03] [04] | |
[01] slice 0.0372 100.0% 192.6% 371.5% 3371.3% | |
[02] list 0.0716 51.9% 100.0% 192.9% 1750.8% | |
[03] copy 0.1382 26.9% 51.8% 100.0% 907.6% | |
[04] deep copy 1.2542 3.0% 5.7% 11.0% 100.0% | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment