angular-cn/packages/core/test/render3/perf
Miško Hevery 4800fa1c08 refactor(core): tweek micro-benchmarks to make them more consistent (#33207)
```
┌────────────────────────────────────┬─────────┬──────┬───────────┬───────────┬───────┐
│              (index)               │  time   │ unit │ base_time │ base_unit │   %   │
├────────────────────────────────────┼─────────┼──────┼───────────┼───────────┼───────┤
│       directive_instantiate        │  2.474  │ 'us' │   2.507   │   'us'    │ -1.32 │
│        element_text_create         │  1.313  │ 'us' │   1.319   │   'us'    │ -0.45 │
│           interpolation            │ 220.17  │ 'us' │  224.217  │   'us'    │ -1.8  │
│             listeners              │  1.988  │ 'us' │   2.021   │   'us'    │ -1.63 │
│ map_based_style_and_class_bindings │ 17.908  │ 'ms' │  18.523   │   'ms'    │ -3.32 │
│       noop_change_detection        │ 24.851  │ 'us' │  24.874   │   'us'    │ -0.09 │
│          property_binding          │ 218.76  │ 'us' │  216.736  │   'us'    │ 0.93  │
│      property_binding_update       │ 443.175 │ 'us' │  447.686  │   'us'    │ -1.01 │
│      style_and_class_bindings      │  1.053  │ 'ms' │   1.069   │   'ms'    │ -1.5  │
│           style_binding            │ 488.154 │ 'us' │  484.092  │   'us'    │ 0.84  │
└────────────────────────────────────┴─────────┴──────┴───────────┴───────────┴───────┘
```

PR Close #33207
2019-10-17 14:13:16 -04:00
..
directive_instantiate refactor(core): tweek micro-benchmarks to make them more consistent (#33207) 2019-10-17 14:13:16 -04:00
element_text_create refactor(core): tweek micro-benchmarks to make them more consistent (#33207) 2019-10-17 14:13:16 -04:00
interpolation perf(ivy): convert all node-based benchmark to use a testing harness (#32699) 2019-09-16 09:31:15 -07:00
listeners perf(ivy): move attributes array into component def (#32798) 2019-10-09 13:16:55 -07:00
map_based_style_and_class_bindings refactor(ivy): move `styling/instructions.ts` to `instructions/styling.ts` (#32731) 2019-09-18 15:06:39 -07:00
noop_change_detection perf(ivy): convert all node-based benchmark to use a testing harness (#32699) 2019-09-16 09:31:15 -07:00
property_binding perf(ivy): convert all node-based benchmark to use a testing harness (#32699) 2019-09-16 09:31:15 -07:00
property_binding_update refactor(ivy): improve micro-benchmark profiling (#32647) 2019-09-12 13:06:38 -07:00
style_and_class_bindings perf(ivy): move attributes array into component def (#32798) 2019-10-09 13:16:55 -07:00
style_binding refactor(ivy): move `styling/instructions.ts` to `instructions/styling.ts` (#32731) 2019-09-18 15:06:39 -07:00
BUILD.bazel perf(ivy): introduce micro-benchmark for directive instantiation (#33082) 2019-10-10 13:56:52 -07:00
README.md refactor(core): tweek micro-benchmarks to make them more consistent (#33207) 2019-10-17 14:13:16 -04:00
micro_bench.ts refactor(core): tweek micro-benchmarks to make them more consistent (#33207) 2019-10-17 14:13:16 -04:00
noop_renderer.ts perf(ivy): add static attributes to the element_text_create benchmark (#32997) 2019-10-08 13:02:11 -07:00
profile_all.js test: Add script which allows running all of the profiling tests and compare results (#33186) 2019-10-16 10:22:30 -04:00
setup.ts perf(ivy): move attributes array into component def (#32798) 2019-10-09 13:16:55 -07:00

README.md

Build

yarn bazel build //packages/core/test/render3/perf:${BENCHMARK}.min_debug.es2015.js --define=compile=aot

Run

node dist/bin/packages/core/test/render3/perf/${BENCHMARK}.min_debug.es2015.js

Profile

node --no-turbo-inlining --inspect-brk dist/bin/packages/core/test/render3/perf/${BENCHMARK}.min_debug.es2015.js

then connect with a debugger (the --inspect-brk option will make sure that benchmark execution doesn't start until a debugger is connected and the code execution is manually resumed).

The actual benchmark code has calls that will start (console.profile) and stop (console.profileEnd) a profiling session.

Run All

To run all of the benchmarks use the profile_all.js script:

node packages/core/test/render3/perf/profile_all.js

NOTE: This command will build all of the tests, so there is no need to do so manually.

Optionally use the --write command to save the run result to a file for later comparison.

node packages/core/test/render3/perf/profile_all.js --write baseline.json

Comparing Runs

If you have saved the baseline (as described in the step above) you can use it to get change in performance like so:

node packages/core/test/render3/perf/profile_all.js --read baseline.json

The resulting output should look something like this:

┌────────────────────────────────────┬─────────┬──────┬───────────┬───────────┬───────┐
│              (index)               │  time   │ unit │ base_time │ base_unit │   %   │
├────────────────────────────────────┼─────────┼──────┼───────────┼───────────┼───────┤
│       directive_instantiate        │ 276.652 │ 'ms' │  286.292  │   'ms'    │ -3.37 │
│        element_text_create         │ 262.868 │ 'ms' │  260.031  │   'ms'    │ 1.09  │
│           interpolation            │ 257.733 │ 'us' │  260.489  │   'us'    │ -1.06 │
│             listeners              │  1.997  │ 'us' │   1.985   │   'us'    │  0.6  │
│ map_based_style_and_class_bindings │  10.07  │ 'ms' │   9.786   │   'ms'    │  2.9  │
│       noop_change_detection        │ 93.256  │ 'us' │  91.745   │   'us'    │ 1.65  │
│          property_binding          │ 290.777 │ 'us' │  280.586  │   'us'    │ 3.63  │
│      property_binding_update       │ 588.545 │ 'us' │  583.334  │   'us'    │ 0.89  │
│      style_and_class_bindings      │  1.061  │ 'ms' │   1.047   │   'ms'    │ 1.34  │
│           style_binding            │ 543.841 │ 'us' │  545.385  │   'us'    │ -0.28 │
└────────────────────────────────────┴─────────┴──────┴───────────┴───────────┴───────┘

Notes

In all the above commands ${BENCHMARK} should be replaced with the actual benchmark (folder) name, ex.:

  • build: yarn bazel build //packages/core/test/render3/perf:noop_change_detection.min_debug.es2015.js --define=compile=aot
  • run: time node dist/bin/packages/core/test/render3/perf/noop_change_detection.min_debug.es2015.js
  • profile: node --no-turbo-inlining --inspect-brk dist/bin/packages/core/test/render3/perf/noop_change_detection.min_debug.es2015.js profile
  • experimenting BENCHMARK=noop_change_detection; yarn bazel build //packages/core/test/render3/perf:${BENCHMARK}.min_debug.es2015.js --define=compile=aot && node dist/bin/packages/core/test/render3/perf/${BENCHMARK}.min_debug.es2015.js