README 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. This is cairo's micro-benchmark performance test suite.
  2. One of the simplest ways to run this performance suite is:
  3. make perf
  4. which will give a report of the speed of each individual test. See
  5. more details on other options for running the suite below.
  6. A macro test suite (with full traces and more intensive benchmarks) is
  7. also available; for this, see http://cgit.freedesktop.org/cairo-traces.
  8. The macro-benchmarks are better measures of actual real-world
  9. performance, and should be preferred over the micro-benchmarks (and over
  10. make perf) for identifying performance regressions or improvements. If
  11. you copy or symlink this repository at cairo/perf/cairo-traces, then
  12. make perf will run those tests as well.
  13. Running the micro-benchmarks
  14. ----------------------------
  15. The micro-benchmark performance suite is composed of a series of
  16. hand-written, short, synthetic tests that measure the speed of doing a
  17. simple operation such as painting a surface or showing glyphs. These aim
  18. to give very good feedback on whether a performance related patch is
  19. successful without causing any performance degradations elsewhere.
  20. The micro-benchmarks are compiled into a single executable called
  21. cairo-perf-micro, which is what "make perf" executes. Some
  22. examples of running it:
  23. # Report on all tests with default number of iterations:
  24. ./cairo-perf-micro
  25. # Report on 100 iterations of all gradient tests:
  26. ./cairo-perf-micro -i 100 gradient
  27. # Generate raw results for 10 iterations into cairo.perf
  28. ./cairo-perf-micro -r -i 10 > cairo.perf
  29. # Append 10 more iterations of the paint test
  30. ./cairo-perf-micro -r -i 10 paint >> cairo.perf
  31. Raw results aren't useful for reading directly, but are quite useful
  32. when using cairo-perf-diff to compare separate runs (see more
  33. below). The advantage of using the raw mode is that test runs can be
  34. generated incrementally and appended to existing reports.
  35. Generating comparisons of separate runs
  36. ---------------------------------------
  37. It's often useful to generate a chart showing the comparison of two
  38. separate runs of the cairo performance suite, (for example, after
  39. applying a patch intended to improve cairo's performance). The
  40. cairo-perf-diff script can be used to compare two report files
  41. generated by cairo-perf.
  42. Again, by way of example:
  43. # Show performance changes from cairo-orig.perf to cairo-patched.perf
  44. ./cairo-perf-diff cairo-orig.perf cairo-patched.perf
  45. This will work whether the data files were generate in raw mode (with
  46. cairo-perf -r) or cooked, (cairo-perf without -r).
  47. Finally, in its most powerful mode, cairo-perf-diff accepts two git
  48. revisions and will do all the work of checking each revision out,
  49. building it, running cairo-perf for each revision, and finally
  50. generating the report. Obviously, this mode only works if you are
  51. using cairo within a git repository, (and not from a tar file). Using
  52. this mode is as simple as passing the git revisions to be compared to
  53. cairo-perf-diff:
  54. # Compare cairo 1.2.6 to cairo 1.4.0
  55. ./cairo-perf-diff 1.2.6 1.4.0
  56. # Measure the impact of the latest commit
  57. ./cairo-perf-diff HEAD~1 HEAD
  58. As a convenience, this common desire to measure a single commit is
  59. supported by passing a single revision to cairo-perf-diff, in which
  60. case it will compare it to the immediately preceding commit. So for
  61. example:
  62. # Measure the impact of the latest commit
  63. ./cairo-perf-diff HEAD
  64. # Measure the impact of an arbitrary commit by SHA-1
  65. ./cairo-perf-diff aa883123d2af90
  66. Also, when passing git revisions to cairo-perf-diff like this, it will
  67. automatically cache results and re-use them rather than re-running
  68. cairo-perf over and over on the same versions. This means that if you
  69. ask for a report that you've generated in the past, cairo-perf-diff
  70. should return it immediately.
  71. Now, sometimes it is desirable to generate more iterations rather than
  72. re-using cached results. In this case, the -f flag can be used to
  73. force cairo-perf-diff to generate additional results in addition to
  74. what has been cached:
  75. # Measure the impact of latest commit (force more measurement)
  76. ./cairo-perf-diff -f
  77. And finally, the -f mode is most useful in conjunction with the --
  78. option to cairo-perf-diff which allows you to pass options to the
  79. underlying cairo-perf runs. This allows you to restrict the additional
  80. test runs to a limited subset of the tests.
  81. For example, a frequently used trick is to first generate a chart with
  82. a very small number of iterations for all tests:
  83. ./cairo-perf-diff HEAD
  84. Then, if any of the results look suspicious, (say there's a slowdown
  85. reported in the text tests, but you think the text test shouldn't be
  86. affected), then you can force more iterations to be tested for only
  87. those tests:
  88. ./cairo-perf-diff -f HEAD -- text
  89. Generating comparisons of different backends
  90. --------------------------------------------
  91. An alternate question that is often asked is, "how does the speed of one
  92. backend compare to another?". cairo-perf-compare-backends can read files
  93. generated by cairo-perf and produces a comparison of the backends for every
  94. test.
  95. Again, by way of example:
  96. # Show relative performance of the backends
  97. ./cairo-perf-compare-backends cairo.perf
  98. This will work whether the data files were generate in raw mode (with
  99. cairo-perf -r) or cooked, (cairo-perf without -r).
  100. Creating a new performance test
  101. -------------------------------
  102. This is where we could use everybody's help. If you have encountered a
  103. sequence of cairo operations that are slower than you would like, then
  104. please provide a performance test. Writing a test is very simple, it
  105. requires you to write only a small C file with a couple of functions,
  106. one of which exercises the cairo calls of interest.
  107. Here is the basic structure of a performance test file:
  108. /* Copyright © 2006 Kind Cairo User
  109. *
  110. * ... Licensing information here ...
  111. * Please copy the MIT blurb as in other tests
  112. */
  113. #include "cairo-perf.h"
  114. static cairo_time_t
  115. do_my_new_test (cairo_t *cr, int width, int height)
  116. {
  117. cairo_perf_timer_start ();
  118. /* Make the cairo calls to be measured */
  119. cairo_perf_timer_stop ();
  120. return cairo_perf_timer_elapsed ();
  121. }
  122. void
  123. my_new_test (cairo_perf_t *perf, cairo_t *cr, int width, int height)
  124. {
  125. /* First do any setup for which the execution time should not
  126. * be measured. For example, this might include loading
  127. * images from disk, creating patterns, etc. */
  128. /* Then launch the actual performance testing. */
  129. cairo_perf_run (perf, "my_new_test", do_my_new_test);
  130. /* Finally, perform any cleanup from the setup above. */
  131. }
  132. That's really all there is to writing a new test. The first function
  133. above is the one that does the real work and returns a timing
  134. number. The second function is the one that will be called by the
  135. performance test rig (see below for how to accomplish that), and
  136. allows for multiple performance cases to be written in one file,
  137. (simply call cairo_perf_run once for each case, passing the
  138. appropriate callback function to each).
  139. We go through this dance of indirectly calling your own function
  140. through cairo_perf_run so that cairo_perf_run can call your function
  141. many times and measure statistical properties over the many runs.
  142. Finally, to fully integrate your new test case you just need to add
  143. your new test to three different lists. (TODO: We should set this up
  144. better so that the lists are maintained automatically---computed from
  145. the list of files in cairo/perf, for example). Here's what needs to be
  146. added:
  147. 1. Makefile.am: Add the new file name to the cairo_perf_SOURCES list
  148. 2. cairo-perf.h: Add a new CAIRO_PERF_DECL line with the name of your
  149. function, (my_new_test in the example above)
  150. 3. cairo-perf-micro.c: Add a new row to the list at the end of the
  151. file. A typical entry would look like:
  152. { my_new_test, 16, 64 }
  153. The last two numbers are a minimum and a maximum image size at
  154. which your test should be exercised. If these values are the same,
  155. then only that size will be used. If they are different, then
  156. intermediate sizes will be used by doubling. So in the example
  157. above, three tests would be performed at sizes of 16x16, 32x32 and
  158. 64x64.
  159. How to run cairo-perf-diff on WINDOWS
  160. -------------------------------------
  161. This section explains the specifics of running cairo-perf-diff under
  162. win32 plateforms. It assumes that you have installed a UNIX-like shell
  163. environment such as MSYS (distributed as part of MinGW).
  164. 1. From your Mingw32 window, be sure to have all of your MSVC environ-
  165. ment variables set up for proper compilation using 'make'
  166. 2. Add the %GitBaseDir%/Git/bin path to your environment, replacing the
  167. %GitBaseDir% by whatever directory your Git version is installed to.
  168. 3. Comment out the "UNSET CDPATH" line in the git-sh-setup script
  169. (located inside the ...Git/bin directory) by putting a "#" at the
  170. beginning of the line.
  171. you should be ready to go !
  172. From your mingw32 window, go to your cairo/perf directory and run the
  173. cairo-perf-diff script with the right arguments.
  174. Thanks for your contributions and have fun with cairo!
  175. TODO
  176. ----
  177. Add a control language for crafting and running small sets of micro
  178. benchmarks.