summaryrefslogtreecommitdiffstats
path: root/src/concurrent/doc/snippets/code
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-07-21 14:24:41 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-07-23 17:19:12 +0200
commit23434f487b05c5230085f61f3f7370e74d3eb6ca (patch)
tree397beaf832df9b6f4759a6396947483d2a6c57f0 /src/concurrent/doc/snippets/code
parentd0f9743d3b6dce647f4cbb6d2b58ce6660f61b62 (diff)
QMap benchmark: use unsigned accumulators and check them
The sum of the first 100000 naturals is more than 2^32, so using an int accumulator to collect the values is susceptible to overflow, which is UB for signed integral types. So switch to an unsigned type. We don't care about the actual sum, only having the various map entries we fetch "used". Since unsigned arithmetic is well-defined even when it overflows, we can calculate the expected sum and verify it, to ensure that no matter how clever the optimizer, it won't throw out the accumulator as written but not read (and then optimize out all the tested code). As a drive-by, rename one of the accumulators to match the rest. Change-Id: I93a2825247c96ca88fe52fdb7ce1e5456eebad54 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/concurrent/doc/snippets/code')
0 files changed, 0 insertions, 0 deletions