Created
June 24, 2019 09:16
-
-
Save ianthetechie/3f9e27dcbae65ff14346c0e637e72f0b to your computer and use it in GitHub Desktop.
Simple test of string concatenation strategies
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
import timeit | |
loop_count = 100 | |
def concat_strings(): | |
out_str = "" | |
for num in range(loop_count): | |
out_str += str(num) | |
return out_str | |
def join_strings(): | |
out_array = [] | |
for num in range(loop_count): | |
out_array.append(str(num)) | |
return "".join(out_array) | |
print(f"concat_strings run time: {timeit.timeit(concat_strings)}s") | |
print(f"join_strings run time: {timeit.timeit(join_strings)}s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment