Debian Codegraph @

devel-docs/rsvg_bench.rst

raw
1 rsvg-bench
2 ==========
3
4 The `rsvg-bench
5 <https://gitlab.gnome.org/GNOME/librsvg/-/tree/main/rsvg-bench>`_
6 program is a small utility for benchmarking librsvg.
7
8 Goals
9 -----
10
11 To benchmark librsvg, we would like to do several things:
12
13 - Be able to process many SVG images with a single command. For
14 example, this lets us answer a question like, "how long does version
15 N of librsvg take to render a directory full of SVG icons?" — which
16 is important for the performance of an application chooser.
17
18 - Be able to **repeatedly** process SVG files, for example, "render this
19 SVG 1000 times in a row". This is useful to get accurate timings,
20 as a single render may only take a few microseconds and may be hard
21 to measure. It also helps with running profilers, as they will be
22 able to get more useful samples if the SVG rendering process runs
23 repeatedly for a long time.
24
25 - Exercise librsvg's major code paths for parsing and rendering
26 separately. For example, librsvg uses different parts of the XML
27 parser depending on whether it is being pushed data, vs. being asked
28 to pull data from a stream. Also, we may only want to benchmark the
29 parser but not the renderer; or we may want to parse SVGs only once
30 but render them many times after that.
31
32 Compiling
33 ---------
34
35 This benchmark is compiled along with ``librsvg``.
36 To compile the benchmark, you need to setup your development or test environment
37 for the ``librsvg`` library. You can follow the instructions in
38 :doc:`devel_environment`.
39
40 You can also simply run ``cargo build --release -p rsvg-bench`` in the
41 root of the ``librsvg`` source tree. This command will compile but the
42 ``librsvg`` library and the ``rsvg-bench`` benchmark, linked together in a
43 static binary. You can run this binary from ``./target/release/rsvg-bench``.
44
45 Usage / benchmarking
46 --------------------
47
48 After compiling it, the ``rsvg-bench`` binary will be available
49 in the ``target/release`` directory of the ``librsvg`` source tree.
50 Please make sure you compiled with ``-release``; when librsvg is
51 installed normally it gets built in release mode (with optimizations),
52 so this will get you meaningful timings.
53
54 You can run the ``rsvg-bench`` binary with the following command line options:
55
56 Running ``target/release/rsvg-bench --help`` will display the help message.
57
58 .. code-block:: bash
59
60 Benchmarking utility for librsvg.
61
62 Usage: rsvg-bench [OPTIONS] [inputs]...
63
64 Arguments:
65 [inputs]... Input files or directories
66
67 Options:
68 --sleep <sleep> Number of seconds to sleep before starting to process SVGs [default: 0]
69 --num-parse <num-parse> Number of times to parse each file [default: 1]
70 --num-render <num-render> Number of times to render each file [default: 1]
71 --hard-failures Stop all processing when a file cannot be rendered
72 -h, --help Print help
73 -V, --version Print version
74
75
76
77 Benchmarking files
78 ------------------
79
80 Rsvg-bench does not extract timings by itself. You can use other
81 tools to do it. ``/usr/bin/time`` is a simple and accurate way (note
82 that this is different from the ``time`` command in most shells).
83
84 Benchmarking all the SVG files in a directory tree
85 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
87 .. code-block:: bash
88
89 /usr/bin/time target/release/rsvg-bench /path/to/svg/files
90
91 This command will benchmark the rendering of all the SVG files in the directory ``/path/to/svg/files``.
92 The benchmark will parse each file once and render it once.
93
94 .. code-block:: bash
95
96 hard_failures: false
97 Will parse each file 1 times
98 Will render each file 1 times
99 Rendering to Cairo image surface
100 Sleeping for 0 seconds before processing SVGs...
101 Processing files!
102 Processing "rsvg/tests/fixtures/text/"
103 Processing "rsvg/tests/fixtures/text/hello-world.svg"
104 Processing "rsvg/tests/fixtures/text/bounds-ref.svg"
105 Processing "rsvg/tests/fixtures/text/display-none.svg"
106 Processing "rsvg/tests/fixtures/text/visibility-hidden.svg"
107 Processing "rsvg/tests/fixtures/text/visibility-hidden-ref.svg"
108 Processing "rsvg/tests/fixtures/text/span-bounds-when-offset-by-dx.svg"
109 Processing "rsvg/tests/fixtures/text/bug806-text-anchor-chunk.svg"
110 Processing "rsvg/tests/fixtures/text/span-bounds-when-offset-by-dx-ref.svg"
111 Processing "rsvg/tests/fixtures/text/visibility-hidden-x-attr.svg"
112 Processing "rsvg/tests/fixtures/text/unicode-bidi-override.svg"
113 Processing "rsvg/tests/fixtures/text/display-none-ref.svg"
114 Processing "rsvg/tests/fixtures/text/bug804-tspan-direction-change-ref.svg"
115 Processing "rsvg/tests/fixtures/text/unicode-bidi-override-ref.svg"
116 Processing "rsvg/tests/fixtures/text/bug804-tspan-direction-change.svg"
117 Processing "rsvg/tests/fixtures/text/bug806-text-anchor-chunk-ref.svg"
118 Processing "rsvg/tests/fixtures/text/bounds.svg"
119 0.28user 0.05system 0:00.29elapsed 114%CPU (0avgtext+0avgdata 31912maxresident)k
120 136inputs+0outputs (2major+1941minor)pagefaults 0swaps
121
122 The output will show the time taken to render each file. The time is in seconds,
123 the number of times each files are parsed and rendered, and the number of files that were processed.
124
125 Benchmarking specific files
126 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
127
128 .. code-block:: bash
129
130 target/release/rsvg-bench /path/to/svg/files/file.svg
131
132 This command will benchmark the rendering of a single SVG file ``/path/to/svg/files/file.svg``.
133 The benchmark will parse the file once and render it once.
134
135 You can also benchmark multiple files by passing their names:
136
137 .. code-block:: bash
138
139 target/release/rsvg-bench /path/to/svg/files/file1.svg /path/to/svg/files/file2.svg /path/to/svg/files/file3.svg
140
141 This command will benchmark the rendering of the SVG files ``/path/to/svg/files/file1.svg``, ``/path/to/svg/files/file2.svg``,
142 and ``/path/to/svg/files/file3.svg``. The benchmark will parse each file once and render it once.
143
144 .. code-block:: bash
145
146 hard_failures: false
147 Will parse each file 1 times
148 Will render each file 1 times
149 Rendering to Cairo image surface
150 Sleeping for 0 seconds before processing SVGs...
151 Processing files!
152 Processing "/path/to/svg/files/file1.svg"
153 Processing "/path/to/svg/files/file2.svg"
154 Processing "/path/to/svg/files/file3.svg"
155 0.28user 0.05system 0:00.29elapsed 114%CPU (0avgtext+0avgdata 31912maxresident)k
156 136inputs+0outputs (2major+1941minor)pagefaults 0swaps
157
158
159 Benchmarking with options
160 -------------------------
161
162 The ``rsvg-bench`` binary has several command line options that can be used to customize the benchmarking process.
163 They are listed above when we ran the `--help` option with the `target/release/rsvg-bench` command.
164 These options are:
165
166 - ``--sleep <sleep>``: Number of seconds to sleep before starting to process SVGs [default: 0]
167 - ``--num-parse <num-parse>``: Number of times to parse each file [default: 1]
168 - ``--num-render <num-render>``: Number of times to render each file [default: 1]
169 - ``--hard-failures``: Stop all processing when a file cannot be rendered
170
171 You can ask ``rsvg-bench`` to sleep for a number of seconds before processing the SVG files.
172 This is useful when you want to give the system some time to settle before
173 starting the benchmarking process and also so that you can attach a profiler
174 to it. For example, ``sysprof <https://blogs.gnome.org/chergert/2016/04/19/how-to-sysprof/>_``
175 lets you choose an already-running process to monitor.
176
177 .. code-block:: bash
178
179 target/release/rsvg-bench --sleep 5 /path/to/svg/files
180
181 This command will benchmark the rendering of all the SVG files in the directory ``/path/to/svg/files``.
182 The benchmark will parse each file once and render it once.
183 The benchmark will sleep for 5 seconds before processing the SVG files.
184
185 .. code-block:: bash
186
187 hard_failures: false
188 Will parse each file 1 times
189 Will render each file 1 times
190 Rendering to Cairo image surface
191 Sleeping for 5 seconds before processing SVGs...
192 Processing files!
193 Processing "rsvg/tests/fixtures/text/"
194 Processing "rsvg/tests/fixtures/text/hello-world.svg"
195 Processing "rsvg/tests/fixtures/text/bounds-ref.svg"
196 Processing "rsvg/tests/fixtures/text/display-none.svg"
197 Processing "rsvg/tests/fixtures/text/visibility-hidden.svg"
198 Processing "rsvg/tests/fixtures/text/visibility-hidden-ref.svg"
199 Processing "rsvg/tests/fixtures/text/span-bounds-when-offset-by-dx.svg"
200 Processing "rsvg/tests/fixtures/text/bug806-text-anchor-chunk.svg"
201 Processing "rsvg/tests/fixtures/text/span-bounds-when-offset-by-dx-ref.svg"
202 Processing "rsvg/tests/fixtures/text/visibility-hidden-x-attr.svg"
203 Processing "rsvg/tests/fixtures/text/unicode-bidi-override.svg"
204 Processing "rsvg/tests/fixtures/text/display-none-ref.svg"
205 Processing "rsvg/tests/fixtures/text/bug804-tspan-direction-change-ref.svg"
206 Processing "rsvg/tests/fixtures/text/unicode-bidi-override-ref.svg"
207 Processing "rsvg/tests/fixtures/text/bug804-tspan-direction-change.svg"
208 Processing "rsvg/tests/fixtures/text/bug806-text-anchor-chunk-ref.svg"
209 Processing "rsvg/tests/fixtures/text/bounds.svg"
210 0.28user 0.05system 0:00.29elapsed 114%CPU (0avgtext+0avgdata 31912maxresident)k
211 136inputs+0outputs (2major+1941minor)pagefaults 0swaps
212
213
214 .. code-block:: bash
215
216 target/release/rsvg-bench --num-parse 2 --num-render 2 /path/to/svg/files
217
218 This command will benchmark the rendering of all the SVG files in the directory ``/path/to/svg/files``.
219 The benchmark will parse each file twice and render it twice.