본문 바로가기
Programming/Python

list method 성능 측정

by Chan_찬 2020. 9. 15.
728x90
반응형

python - list

list 를 만들 때, +, append, comprehension 등을 사용한다
각각의 성능측정 결과, 상황에 맞게 잘 사용하면 좋을 것 같다

le = 1000000
@print_method
def test_concat():  # O(k)
  l=[]
  for i in range(le):
    l+=[i]

@print_method
def test_append():  # O(1)
  l=[]
  for i in range(le):
    l.append(i)

@print_method
def test_comprehension():
  l=[i for i in range(le)]

@print_method
def test_range():
  l=list(range(le))

test_concat()
test_append()
test_comprehension()
test_range()

test_concat: 0.4071
test_append: 0.3272
test_comprehension: 0.1952
test_range: 0.1603
728x90
728x90
BIG
Buy me a coffeeBuy me a coffee

댓글