[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
time complexity of string +=
From: |
Peng Yu |
Subject: |
time complexity of string += |
Date: |
Fri, 12 Mar 2021 09:41:10 -0600 |
Hi,
It seems that the time complexity of string += is super-linear. Is it
so? Should it be made to be linear instead of super-linear?
x=; time for ((i=0;i<100;++i)); do x+=a; done; echo "${#x}"
real 0m0.001s
user 0m0.001s
sys 0m0.000s
100
x=; time for ((i=0;i<10000;++i)); do x+=a; done; echo "${#x}"
real 0m0.058s
user 0m0.057s
sys 0m0.000s
10000
x=; time for ((i=0;i<1000000;++i)); do x+=a; done; echo "${#x}"
real 0m20.997s
user 0m20.969s
sys 0m0.017s
1000000
--
Regards,
Peng
- time complexity of string +=,
Peng Yu <=