Skip to content

Commit ea71ad6

Browse files
committed
test(bench): report the ops each JNI benchmark row executed
Every measureJs and measureCallback row now logs "ops": the operations it ran in the launch, warm-up and reference calls included. A counter run at two scales divided by the ops difference gives counts per operation without hard-coding each row's iteration formula.
1 parent 6aead70 commit ea71ad6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎test-app/app/src/main/assets/app/tests/benchmarks/jniBenchmarks.js‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ function median(values) {
2121
return sorted[Math.floor(sorted.length / 2)];
2222
}
2323

24-
function report(name, nsPerOp, refNsPerOp) {
24+
// ops, when given, is every operation the row executed in this launch (warm-up, reference
25+
// calls and timed rounds): tools/perf/stat.sh divides counter deltas between two scales by it.
26+
function report(name, nsPerOp, refNsPerOp, ops) {
2527
var result = {
2628
name: name,
2729
median: Math.round(median(nsPerOp) * 10) / 10,
@@ -31,6 +33,9 @@ function report(name, nsPerOp, refNsPerOp) {
3133
result.ref = Math.round(median(refNsPerOp) * 10) / 10;
3234
result.refMin = Math.round(Math.min.apply(null, refNsPerOp) * 10) / 10;
3335
}
36+
if (ops) {
37+
result.ops = ops;
38+
}
3439
console.log("JNIBENCH " + JSON.stringify(result));
3540
return result;
3641
}
@@ -39,7 +44,8 @@ function report(name, nsPerOp, refNsPerOp) {
3944
function measureJs(name, iterations, body) {
4045
if (skipped(name)) return null;
4146
iterations *= SCALE;
42-
var sink = body(Math.max(1000, iterations >> 2));
47+
var warmup = Math.max(1000, iterations >> 2);
48+
var sink = body(warmup);
4349
var samples = [];
4450
for (var r = 0; r < ROUNDS; r++) {
4551
var start = performance.now();
@@ -48,7 +54,7 @@ function measureJs(name, iterations, body) {
4854
samples.push((elapsed * 1e6) / iterations);
4955
}
5056
globalThis.__jniBenchSink = sink;
51-
return report(name, samples);
57+
return report(name, samples, null, warmup + ROUNDS * iterations);
5258
}
5359

5460
// Callback rows drift with the device's performance state independently of the other rows,
@@ -65,16 +71,17 @@ function measureCallback(name, cb, kind, iterations) {
6571
if (refCallback === null) {
6672
refCallback = new JniBench.Callback({ twoInts: function (a, b) { } });
6773
}
74+
var warmup = Math.max(1000, iterations >> 2);
6875
JniBench.runCallbacks(refCallback, REF_CALLBACK_KIND, refIterations >> 2);
69-
JniBench.runCallbacks(cb, kind, Math.max(1000, iterations >> 2));
76+
JniBench.runCallbacks(cb, kind, warmup);
7077
var samples = [];
7178
var ref = [];
7279
for (var r = 0; r < ROUNDS; r++) {
7380
ref.push(Number(JniBench.runCallbacks(refCallback, REF_CALLBACK_KIND, refIterations)) / refIterations);
7481
var nanos = JniBench.runCallbacks(cb, kind, iterations);
7582
samples.push(Number(nanos) / iterations);
7683
}
77-
return report(name, samples, ref);
84+
return report(name, samples, ref, (refIterations >> 2) + warmup + ROUNDS * (refIterations + iterations));
7885
}
7986

8087

0 commit comments

Comments
 (0)