Skip to content

Commit 5cdd28b

Browse files
Update string_concatenation_performance.py
1 parent 2522415 commit 5cdd28b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

performance/string_concatenation_performance.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
#############################################################
2+
# | cafe | http://cafe.naver.com/dremdelover |
3+
# | Q&A | https://open.kakao.com/o/gX0WnTCf |
4+
# | business | ultrasuperrok@gmail.com |
5+
#############################################################
6+
# 1. += 연산자 사용: 이 부분에서는 문자열 결합을 위해 += 연산자를 사용합니다. 문자열은 변경이 불가능한 객체이므로,
7+
# 매번 += 연산을 수행할 때마다 새로운 문자열 객체가 생성되고, 이전 문자열의 내용과 새로운 문자열의 내용이 복사됩니다.
8+
# 이로 인해 이 연산은 시간 복잡도 O(n^2)를 가지게 됩니다.
9+
#
10+
# 2. join() 메서드 사용: join() 메서드는 문자열 리스트를 한 번에 결합하는 방법을 제공합니다.
11+
# 이 메서드는 내부적으로 더 효율적인 메모리 관리를 하며, 문자열을 한 번에 합치기 때문에 시간 복잡도 O(n)을 가집니다.
12+
# 따라서, 큰 문자열 리스트에서는 join() 메서드가 += 연산자보다 훨씬 빠른 성능을 보여줍니다.
13+
114
import time
215

316
num_elements = 1000000

0 commit comments

Comments
 (0)