1.. zephyr:code-sample:: zbus-benchmark
2 :name: Benchmarking
3 :relevant-api: zbus_apis
4
5 Measure the time for sending 256KB from a producer to N consumers.
6
7This sample implements an application to measure the time for sending 256KB from the producer to the
8consumers.
9
10Building and Running
11********************
12
13.. zephyr-app-commands::
14 :zephyr-app: samples/subsys/zbus/dyn_channel
15 :host-os: unix
16 :board: qemu_cortex_m3
17 :gen-args: -DCONFIG_BM_MESSAGE_SIZE=512 -DCONFIG_BM_ONE_TO=1 -DCONFIG_BM_LISTENERS=y
18 :goals: build run
19
20Notice we have the following parameters:
21
22* **CONFIG_BM_MESSAGE_SIZE** the size of the message to be transferred (2 to 4096 bytes);
23* **CONFIG_BM_ONE_TO** number of consumers to send (1 up to 8 consumers);
24* **CONFIG_BM_LISTENERS** Use y to perform the benchmark listeners;
25* **CONFIG_BM_SUBSCRIBERS** Use y to perform the benchmark subscribers;
26* **CONFIG_BM_MSG_SUBSCRIBERS** Use y to perform the benchmark message subscribers.
27
28Sample Output
29=============
30The result would be something like:
31
32.. code-block:: console
33
34 *** Booting Zephyr OS build zephyr-vX.Y.Z ***
35 I: Benchmark 1 to 1 using LISTENERS to transmit with message size: 512 bytes
36 I: Bytes sent = 262144, received = 262144
37 I: Average data rate: 12.62MB/s
38 I: Duration: 0.019805908s
39
40 @19805
41
42
43Running the benchmark automatically
44===================================
45
46There is a `Robot framework <https://robotframework.org/>`_ script called ``benchmark_256KB.robot`` which runs all the input combinations as the complete benchmark.
47The resulting file, ``zbus_dyn_benchmark_256KB.csv`` is generated in the project root folder. It takes a long time to execute. In the CSV file, we have the following columns:
48
49+-----------------+---------------------+--------------------------+---------------+-------------+-------------+
50| Observer type | Number of consumers | Message size (bytes) | Duration (ns) | RAM (bytes) | ROM (bytes) |
51+=================+=====================+==========================+===============+=============+=============+
52| LIS/SUB/MSG_SUB | 1,4,8 | 2,8,32,128,512 | float | int | int |
53+-----------------+---------------------+--------------------------+---------------+-------------+-------------+
54
55The complete benchmark command using Robot framework is:
56
57.. code-block:: console
58
59 robot --variable serial_port:/dev/ttyACM0 --variable board:nrf52dk/nrf52832 -d /tmp/benchmark_out benchmark_256KB.robot
60
61An example of execution using the ``nrf52dk/nrf52832`` board would generate a file like this:
62
63.. code-block::
64
65 LISTENERS,1,2,890787.3333333334,9247,23091
66 LISTENERS,1,8,237925.0,9253,23091
67 LISTENERS,1,32,74513.0,9277,23151
68 LISTENERS,1,128,33813.0,9565,23231
69 LISTENERS,1,512,35746.0,10717,23623
70 LISTENERS,4,2,314198.3333333333,9274,23142
71 LISTENERS,4,8,82244.33333333333,9280,23142
72 LISTENERS,4,32,24057.333333333332,9304,23202
73 LISTENERS,4,128,9816.0,9592,23282
74 LISTENERS,4,512,9277.0,10744,23674
75 LISTENERS,8,2,211465.66666666666,9310,23202
76 LISTENERS,8,8,56294.0,9316,23210
77 LISTENERS,8,32,15635.0,9340,23270
78 LISTENERS,8,128,5818.0,9628,23350
79 LISTENERS,8,512,4862.0,10780,23742
80 SUBSCRIBERS,1,2,7804351.333333333,9927,23463
81 SUBSCRIBERS,1,8,1978179.3333333333,9933,23463
82 SUBSCRIBERS,1,32,514139.3333333333,9957,23523
83 SUBSCRIBERS,1,128,146759.0,10309,23603
84 SUBSCRIBERS,1,512,55104.0,11845,23995
85 SUBSCRIBERS,4,2,5551961.0,11994,24134
86 SUBSCRIBERS,4,8,1395009.0,12000,24134
87 SUBSCRIBERS,4,32,354583.3333333333,12024,24194
88 SUBSCRIBERS,4,128,92976.66666666667,12568,24274
89 SUBSCRIBERS,4,512,28015.0,15256,24666
90 SUBSCRIBERS,8,2,5449839.0,14750,24858
91 SUBSCRIBERS,8,8,1321766.6666666667,14756,24866
92 SUBSCRIBERS,8,32,332804.0,14780,24926
93 SUBSCRIBERS,8,128,85489.33333333333,15580,25006
94 SUBSCRIBERS,8,512,23905.0,19804,25398
95 MSG_SUBSCRIBERS,1,2,8783538.333333334,10371,25615
96 MSG_SUBSCRIBERS,1,8,2249592.6666666665,10377,25615
97 MSG_SUBSCRIBERS,1,32,610168.0,10401,25675
98 MSG_SUBSCRIBERS,1,128,207295.0,10753,25755
99 MSG_SUBSCRIBERS,1,512,143584.66666666666,12289,26147
100 MSG_SUBSCRIBERS,4,2,5787699.0,12318,26126
101 MSG_SUBSCRIBERS,4,8,1473907.0,12324,26126
102 MSG_SUBSCRIBERS,4,32,396127.6666666667,12348,26186
103 MSG_SUBSCRIBERS,4,128,126362.66666666667,12892,26266
104 MSG_SUBSCRIBERS,4,512,59040.666666666664,15580,26658
105 MSG_SUBSCRIBERS,8,2,5453999.333333333,14914,26610
106 MSG_SUBSCRIBERS,8,8,1356312.3333333333,14920,26650
107 MSG_SUBSCRIBERS,8,32,361368.3333333333,14944,26710
108 MSG_SUBSCRIBERS,8,128,113148.66666666667,15744,26790
109 MSG_SUBSCRIBERS,8,512,51218.333333333336,19968,27182
110