qt5base-lts/tests/benchmarks
Igor Kushnir 7c9597ef56 Add QSortFilterProxyModel clear-filter benchmark
Use QBENCHMARK_ONCE rather than QBENCHMARK to avoid skewing the results:
when the QBENCHMARK block is repeated multiple times after the setup
code above runs once, only the first setFilterRegularExpression() call
unfilters some rows, while the subsequent calls simply check that there
is nothing to do.

The added benchmark is sensitive to the inefficiency - quadratic rather
than linear time complexity - fixed by
7d92ef63d7. The following two tables
contain the benchmark results on my GNU/Linux system. The numbers denote
milliseconds per iteration.

1. Qt 5.15.2 without the performance fix:
                    10K 25K 50K     100K    250K    500K
       no match     0    1    2       5       14       28
            all     0    0    0       1        3        7
          first     0    1    2       5       14       28
         1000th     2    6   12      25       68      302
         middle     3   34  132     518     3300    13665
1000th from end     1    4    9      19       50      103
           last     0    1    2       5       14       30
  each 10'000th     0   39  211     937     6326    41050
 each 100'000th     0    1    2       5     4226    34780

Without the fix the benchmark times out and aborts at 1000K and 2000K
data rows.

2. Qt 5.15.2 with the performance fix:
                    10K 25K 50K 100K    250K    500K    1000K   2000K
       no match     0   1   2   4       12      26       56      136
            all     0   0   0   1        3       7       14       28
          first     0   1   2   4       12      26       56      136
         1000th     0   1   2   4       13      28       62      145
         middle     0   1   2   4       13      27       59      142
1000th from end     0   1   2   4       13      28       60      145
           last     0   1   2   4       13      27       59      141
  each 10'000th     0   1   2   6       22      69      290     1413
 each 100'000th     0   1   2   4       13      30       81      261

Change-Id: I419a5521dd0be7676fbb09b34b4069d4a76423b1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2021-04-25 13:25:01 +03:00
..
corelib Add QSortFilterProxyModel clear-filter benchmark 2021-04-25 13:25:01 +03:00
dbus Fix a few compiler warnings in tests 2021-02-02 12:06:05 +01:00
gui Replace deprecated APIs in metatype/variant benchmarks 2021-04-14 14:38:42 +02:00
network Convert QSslSocket(Backend)Private into plugin 2021-03-17 16:25:37 +01:00
plugins/imageformats/jpeg Remove qmake project files for benchmarks 2021-02-01 21:14:01 +01:00
sql Remove qmake project files for benchmarks 2021-02-01 21:14:01 +01:00
testlib Remove qmake project files for benchmarks 2021-02-01 21:14:01 +01:00
widgets Fix some warnings 2021-03-29 16:06:25 +02:00
CMakeLists.txt Convert remaining tests/benchmarks 2019-11-04 15:48:51 +00:00
README Whitespace cleanup: remove trailing whitespace 2013-03-16 20:22:50 +01:00

The most reliable way of running benchmarks is to do it in an otherwise idle
system. On a busy system, the results will vary according to the other tasks
demanding attention in the system.

We have managed to obtain quite reliable results by doing the following on
Linux (and you need root):

 - switching the scheduler to a Real-Time mode
 - setting the processor affinity to one single processor
 - disabling the other thread of the same core

This should work rather well for CPU-intensive tasks. A task that is in Real-
Time mode will simply not be preempted by the OS. But if you make OS syscalls,
especially I/O ones, your task will be de-scheduled. Note that this includes
page faults, so if you can, make sure your benchmark's warmup code paths touch
most of the data.

To do this you need a tool called schedtool (package schedtool), from
http://freequaos.host.sk/schedtool/

From this point on, we are using CPU0 for all tasks:

If you have a Hyperthreaded multi-core processor (Core-i5 and Core-i7), you
have to disable the other thread of the same core as CPU0. To discover which
one it is:

$ cat /sys/devices/system/cpu/cpu0/topology/thread_siblings_list

This will print something like 0,4, meaning that CPUs 0 and 4 are sibling
threads on the same core. So we'll turn CPU 4 off:

(as root)
# echo 0 > /sys/devices/system/cpu/cpu4/online

To turn it back on, echo 1 into the same file.

To run a task on CPU 0 exclusively, using FIFO RT priority 10, you run the
following:

(as root)
# schedtool -F -p 10 -a 1 -e ./taskname

For example:
# schedtool -F -p 10 -a 1 -e ./tst_bench_qstring -tickcounter

Warning: if your task livelocks or takes far too long to complete, your system
may be unusable for a long time, especially if you don't have other cores to
run stuff on. To prevent that, run it before schedtool and time it.

You can also limit the CPU time that the task is allowed to take. Run in the
same shell as you'll run schedtool:

$ ulimit -s 300
To limit to 300 seconds (5 minutes)

If your task runs away, it will get a SIGXCPU after consuming 5 minutes of CPU
time (5 minutes running at 100%).

If your app is multithreaded, you may want to give it more CPUs, like CPU0 and
CPU1 with -a 3  (it's a bitmask).

For best results, you should disable ALL other cores and threads of the same
processor. The new Core-i7 have one processor with 4 cores,
each core can run 2 threads; the older Mac Pros have two processors with 4
cores each. So on those Mac Pros, you'd disable cores 1, 2 and 3, while on the
Core-i7, you'll need to disable all other CPUs.

However, disabling just the sibling thread seems to produce very reliable
results for me already, with variance often below 0.5% (even though there are
some measurable spikes).

Other things to try:

Running the benchmark with highest priority, i.e. "sudo nice -19"
usually produces stable results on some machines. If the benchmark also
involves displaying something on the screen (on X11), running it with
"-sync" is a must. Though, in that case the "real" cost is not correct,
but it is useful to discover regressions.

Also; not many people know about ionice (1)
      ionice - get/set program io scheduling class and priority