starlark benchmark: allow filtering on filename and function
PiperOrigin-RevId: 343204476
diff --git a/src/test/java/net/starlark/java/eval/Benchmarks.java b/src/test/java/net/starlark/java/eval/Benchmarks.java
index 3b130e7..f705278 100644
--- a/src/test/java/net/starlark/java/eval/Benchmarks.java
+++ b/src/test/java/net/starlark/java/eval/Benchmarks.java
@@ -63,7 +63,10 @@
private static final String HELP =
"Usage: Benchmarks [--help] [--filter regex] [--seconds float]\n"
+ "Runs Starlark benchmarks matching the filter for the specified (approximate) time,\n"
- + "and reports various performance measures.";
+ + "and reports various performance measures.\n"
+ + "The optional filter is a regular expression applied to the string FILE:FUNC,\n"
+ + "where FILE is the base name of the file and FUNC is the name of the function,\n"
+ + "for example 'bench_int.star:bench_add32'.\n";
private static boolean ok = true;
@@ -120,7 +123,8 @@
}
File testdata = new File(src, "test/java/net/starlark/java/eval/testdata");
for (File file : testdata.listFiles()) {
- if (!(file.getName().startsWith("bench_") && file.getName().endsWith(".star"))) {
+ String basename = file.getName();
+ if (!(basename.startsWith("bench_") && basename.endsWith(".star"))) {
continue;
}
@@ -159,8 +163,9 @@
TreeMap<String, StarlarkFunction> benchmarks = new TreeMap<>();
for (Map.Entry<String, Object> e : module.getExportedGlobals().entrySet()) {
if (e.getKey().startsWith("bench_") && e.getValue() instanceof StarlarkFunction) {
- if (filter == null || filter.matcher(e.getKey()).find()) {
- benchmarks.put(e.getKey(), (StarlarkFunction) e.getValue());
+ String name = e.getKey();
+ if (filter == null || filter.matcher(basename + ":" + name).find()) {
+ benchmarks.put(name, (StarlarkFunction) e.getValue());
}
}
}
diff --git a/src/test/java/net/starlark/java/eval/testdata/bench_sorted.star b/src/test/java/net/starlark/java/eval/testdata/bench_sorted.star
index 2c55735..35de675 100644
--- a/src/test/java/net/starlark/java/eval/testdata/bench_sorted.star
+++ b/src/test/java/net/starlark/java/eval/testdata/bench_sorted.star
@@ -12,10 +12,10 @@
copy = orig[:] # TODO(adonovan): move allocation outside loop
sorted(copy)
-def bench_sort_large(b):
+def bench_large(b):
"Sort an array of a million ints."
_bench_sort(b, 1000000)
-def bench_sort_small(b):
+def bench_small(b):
"Sort an array of ten ints."
_bench_sort(b, 10)