b134718c11
operator=(~) and assign() share similar names but, until now, have not shared the same functionality. This patch introduces the usage of QString::assign() within the non-sharing assignment operators to effectively boost efficiency by reusing the available capacity. Since we're re-using the capacity we update the test case in places where they don't hold true anymore. Since these assignment operators are frequently used in many places, both within Qt and non-Qt code, this patch comes with benchmarks. The preview of the benchmark results are compared with this patch and before this patch. The results show a boost in performance for the QByteArray and 'const char*' overload. The QLatin1StringView overload already preserved the capacity and has a better performance than the assign() alternative, so don't us it there. (x86_64-little_endian-lp64 shared (dynamic) release build (O3); by gcc 13.2.1, endeavouros ; 13th Gen Intel(R) Core(TM) i9-13900K benchmarks executed with -perf -iterations 1000000 * The last value at the EOL represent the string size. QString &operator=(const QByteArray &a) (current) 64.3 cycles/iter; 300 instructions/iter; 17 nsec/iter (5) 65.8 cycles/iter; 366 instructions/iter; 12 nsec/iter (10) 62.9 cycles/iter; 301 instructions/iter; 11.5 nsec/iter (20) 61.3 cycles/iter; 315 instructions/iter; 11.1 nsec/iter (50) 71.4 cycles/iter; 386 instructions/iter; 13 nsec/iter (100) 136.9 cycles/iter; 811 instructions/iter; 24.5 nsec/iter (500) 245.8 cycles/iter; 1394 instructions/iter; 42.5 nsec/iter (1'000) QString &operator=(const QByteArray &a) (before) 78 cycles/iter; 399 instructions/iter; 15.3 nsec/iter (5) 82.3 cycles/iter; 465 instructions/iter; 15 nsec/iter (10) 76.7 cycles/iter; 400 instructions/iter; 14 nsec/iter (20) 79.5 cycles/iter; 414 instructions/iter; 14.5 nsec/iter (50) 91.4 cycles/iter; 485 instructions/iter; 16.7 nsec/iter (100) 189 cycles/iter; 910 instructions/iter; 34.4 nsec/iter (500) 320 cycles/iter; 1666 instructions/iter; 56 nsec/iter (1'000) QString &operator=(const char *ch) (current) 70 cycles/iter; 317 instructions/iter; 12 nsec/iter (5) 71 cycles/iter; 383 instructions/iter; 12.3 nsec/iter (10) 64 cycles/iter; 318 instructions/iter; 11.1 nsec/iter (20) 69 cycles/iter; 340 instructions/iter; 12 nsec/iter (50) 77 cycles/iter; 419 instructions/iter; 13.5 nsec/iter (100) 141 cycles/iter; 899 instructions/iter; 24.4 nsec/iter (500) 280 cycles/iter; 1518 instructions/iter; 48.4 nsec/iter (1'000) QString &operator=(const char *ch) (before) 86.7 cycles/iter; 416 instructions/iter; 15 nsec/iter (5) 87.8 cycles/iter; 482 instructions/iter; 15.7 nsec/iter (10) 82.4 cycles/iter; 417 instructions/iter; 14.3 nsec/iter (20) 90.2 cycles/iter; 443 instructions/iter; 15.6 nsec/iter (50) 101.4 cycles/iter; 518 instructions/iter; 17.7 nsec/iter (100) 204.4 cycles/iter; 994 instructions/iter; 36.5 nsec/iter (500) 337.9 cycles/iter; 1789 instructions/iter; 58.9 nsec/iter (1'000) * current implemented as: assign(other) QString &operator=(QLatin1StringView other) (current) 47.4 cycles/iter; 237 instructions/iter; 8.2 nsec/iter (5) 46.2 cycles/iter; 237 instructions/iter; 7.9 nsec/iter (10) 46.8 cycles/iter; 255 instructions/iter; 8 nsec/iter (20) 59 cycles/iter; 273 instructions/iter; 10.2 nsec/iter (50) 55 cycles/iter; 300 instructions/iter; 9.5 nsec/iter (100) 94.3 cycles/iter; 525 instructions/iter; 16.3 nsec/iter (500) 166 cycles/iter; 804 instructions/iter; 28.7 nsec/iter (1'000) QString &operator=(QLatin1StringView other) (before) 14 cycles/iter; 79 instructions/iter; 2.5 nsec/iter (5) 14 cycles/iter; 79 instructions/iter; 2.6 nsec/iter (10) 16 cycles/iter; 97 instructions/iter; 3 nsec/iter (20) 19 cycles/iter; 115 instructions/iter; 3.5 nsec/iter (50) 23 cycles/iter; 142 instructions/iter; 4.2 nsec/iter (100) 91 cycles/iter; 367 instructions/iter; 16.6 nsec/iter (500) 131 cycles/iter; 646 instructions/iter; 23.4 nsec/iter (1'000) Task-number: QTBUG-106201 Change-Id: Ie852f6abd1cf16164802acddb048eae5df59758f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> |
||
---|---|---|
.github/workflows | ||
bin | ||
cmake | ||
coin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
libexec | ||
LICENSES | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.cmake.conf | ||
.gitattributes | ||
.gitignore | ||
.lgtm.yml | ||
.tag | ||
CMakeLists.txt | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.cmake | ||
dependencies.yaml | ||
qt_cmdline.cmake |