1*2d1272b8SAndroid Build Coastguard Worker# Building and Running 2*2d1272b8SAndroid Build Coastguard Worker 3*2d1272b8SAndroid Build Coastguard WorkerBenchmarks are implemented using [Google Benchmark](https://github.com/google/benchmark). 4*2d1272b8SAndroid Build Coastguard Worker 5*2d1272b8SAndroid Build Coastguard WorkerTo build the benchmarks in this directory you need to set the benchmark 6*2d1272b8SAndroid Build Coastguard Workeroption while configuring the build with meson: 7*2d1272b8SAndroid Build Coastguard Worker 8*2d1272b8SAndroid Build Coastguard Worker``` 9*2d1272b8SAndroid Build Coastguard Workermeson build -Dbenchmark=enabled --buildtype=release 10*2d1272b8SAndroid Build Coastguard Worker``` 11*2d1272b8SAndroid Build Coastguard Workeror: 12*2d1272b8SAndroid Build Coastguard Worker``` 13*2d1272b8SAndroid Build Coastguard Workermeson build -Dbenchmark=enabled --buildtype=debugoptimized 14*2d1272b8SAndroid Build Coastguard Worker``` 15*2d1272b8SAndroid Build Coastguard Worker 16*2d1272b8SAndroid Build Coastguard Worker 17*2d1272b8SAndroid Build Coastguard WorkerThen build a specific benchmark binaries with ninja: 18*2d1272b8SAndroid Build Coastguard Worker``` 19*2d1272b8SAndroid Build Coastguard Workerninja -Cbuild perf/benchmark-set 20*2d1272b8SAndroid Build Coastguard Worker``` 21*2d1272b8SAndroid Build Coastguard Workeror just build the whole project: 22*2d1272b8SAndroid Build Coastguard Worker``` 23*2d1272b8SAndroid Build Coastguard Workerninja -Cbuild 24*2d1272b8SAndroid Build Coastguard Worker``` 25*2d1272b8SAndroid Build Coastguard Worker 26*2d1272b8SAndroid Build Coastguard WorkerFinally, to run one of the benchmarks: 27*2d1272b8SAndroid Build Coastguard Worker 28*2d1272b8SAndroid Build Coastguard Worker``` 29*2d1272b8SAndroid Build Coastguard Worker./build/perf/benchmark-set 30*2d1272b8SAndroid Build Coastguard Worker``` 31*2d1272b8SAndroid Build Coastguard Worker 32*2d1272b8SAndroid Build Coastguard WorkerIt's possible to filter the benchmarks being run and customize the output 33*2d1272b8SAndroid Build Coastguard Workervia flags to the benchmark binary. See the 34*2d1272b8SAndroid Build Coastguard Worker[Google Benchmark User Guide](https://github.com/google/benchmark/blob/main/docs/user_guide.md#user-guide) for more details. 35*2d1272b8SAndroid Build Coastguard Worker 36*2d1272b8SAndroid Build Coastguard Worker# Profiling 37*2d1272b8SAndroid Build Coastguard Worker 38*2d1272b8SAndroid Build Coastguard WorkerConfigure the build to include debug information for profiling: 39*2d1272b8SAndroid Build Coastguard Worker 40*2d1272b8SAndroid Build Coastguard Worker``` 41*2d1272b8SAndroid Build Coastguard WorkerCXXFLAGS="-fno-omit-frame-pointer" meson --reconfigure build -Dbenchmark=enabled --buildtype=debug 42*2d1272b8SAndroid Build Coastguard Workerninja -Cbuild 43*2d1272b8SAndroid Build Coastguard Worker``` 44*2d1272b8SAndroid Build Coastguard Worker 45*2d1272b8SAndroid Build Coastguard WorkerThen run the benchmark with perf: 46*2d1272b8SAndroid Build Coastguard Worker 47*2d1272b8SAndroid Build Coastguard Worker``` 48*2d1272b8SAndroid Build Coastguard Workerperf record -g build/perf/benchmark-subset --benchmark_filter="BM_subset_codepoints/subset_notocjk/100000" --benchmark_repetitions=5 49*2d1272b8SAndroid Build Coastguard Worker``` 50*2d1272b8SAndroid Build Coastguard WorkerYou probably want to filter to a specific benchmark of interest and set the number of repititions high enough to get a good sampling of profile data. 51*2d1272b8SAndroid Build Coastguard Worker 52*2d1272b8SAndroid Build Coastguard WorkerFinally view the profile with: 53*2d1272b8SAndroid Build Coastguard Worker 54*2d1272b8SAndroid Build Coastguard Workerperf report 55