starlark: a simple benchmark runner

This change adds a simple benchmark runner, modelled on Go's testing.B
(https://golang.org/pkg/testing/#B). See also discussion in
https://github.com/bazelbuild/starlark/pull/75#pullrequestreview-275604129.
And https://github.com/bazelbuild/bazel/pull/9195, a JMH-based approach.
(Although JMH's measurement logic is of high quality, sadly it cannot be used
without annotations, which makes it unsuitable for a completely dynamic suite
such as this one.)

Each function named bench_* in a file named bench_*.star is executed repeatedly
by the runner. The runner provides a parameter, b, that gives, among other things,
the number b.n of operations to attempt, and operations to stop, start,
or restart the timer.

Output:
$ bazel run src/test/java/net/starlark/java/eval/Benchmarks
File src/test/java/net/starlark/java/eval/testdata/bench_list.star:
benchmark                   ops     cpu/op    wall/op   steps/op
bench_append               8191      186µs      183µs       5004
bench_extend            2097151      664ns      618ns          7

File src/test/java/net/starlark/java/eval/testdata/bench_sorted.star:
benchmark                   ops     cpu/op    wall/op   steps/op
bench_sort_large             31  40.2619ms  37.3016ms          7
bench_sort_small        4194303      346ns      346ns          7
PiperOrigin-RevId: 342904761
4 files changed
tree: 57e3f160f28471e669464daf16a7f12f69db80f6
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEBASE.md
  15. CODEOWNERS
  16. combine_distfiles.py
  17. combine_distfiles_to_tar.sh
  18. compile.sh
  19. CONTRIBUTING.md
  20. CONTRIBUTORS
  21. distdir.bzl
  22. ISSUE_TEMPLATE.md
  23. LICENSE
  24. README.md
  25. WORKSPACE
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status