https://github.com/buchgr/rules_jmh
Bazel rules for generating and running microbenchmarks with JMH
https://github.com/buchgr/rules_jmh
Last synced: 6 months ago
JSON representation
Bazel rules for generating and running microbenchmarks with JMH
- Host: GitHub
- URL: https://github.com/buchgr/rules_jmh
- Owner: buchgr
- Created: 2019-04-08T09:50:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-17T11:16:36.000Z (over 3 years ago)
- Last Synced: 2025-03-28T07:22:44.118Z (6 months ago)
- Language: Python
- Size: 4.88 KB
- Stars: 11
- Watchers: 1
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rules_jmh
Bazel rules for generating and running microbenchmarks with [JMH](https://openjdk.java.net/projects/code-tools/jmh/).
# Usage
Load the JMH dependencies in your WORKSPACE file
```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")http_archive(
name = "rules_jmh",
strip_prefix = "buchgr-rules_jmh-6ccf8d7",
url = "https://github.com/buchgr/rules_jmh/zipball/6ccf8d7b270083982e5c143935704b9f3f18b256",
type = "zip",
sha256 = "dbb7d7e5ec6e932eddd41b910691231ffd7b428dff1ef9a24e4a9a59c1a1762d",
)load("@rules_jmh//:deps.bzl", "rules_jmh_deps")
rules_jmh_deps()
load("@rules_jmh//:defs.bzl", "rules_jmh_maven_deps")
rules_jmh_maven_deps()
```You can specify JMH benchmarks by using the `jmh_java_benchmarks` rule. It takes the same arguments as `java_binary` except for `main_class`. One can specify one or more JMH benchmarks in the `srcs` attribute.
```python
load("@rules_jmh//:defs.bzl", "jmh_java_benchmarks")jmh_java_benchmarks(
name = "example-benchmarks",
srcs = ["Benchmark1.java", "Benchmark2.java"]
)
```You can run the benchmark `//:example-benchmarks` using `bazel run`.
```sh
$ bazel run :example-benchmarks
```and also pass JMH command line flags
```sh
$ bazel run :example-benchmarks -- -f 0 -bm avgt
```Alternatively you can also build a standalone fat (deploy) jar that contains all dependencies and can be run without Bazel
```sh
# Build the jar file
$ bazel build :example-benchmarks_deploy.jar
# Shutdown Bazel for it to not interfere with your benchmark
$ bazel shutdown
# Run the benchmark
$ java -jar bazel-bin/example-benchmarks_deploy.jar
```