[pathkit] Clean up perf/test init
This will hopefully help with flakiness.
Bug: skia:8810
Change-Id: Id2fa9abcc0e95f0cf8b08557215766b4f9c57478
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/200047
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
diff --git a/modules/pathkit/perf/effects.bench.js b/modules/pathkit/perf/effects.bench.js
index cf73fd4..30d6e35 100644
--- a/modules/pathkit/perf/effects.bench.js
+++ b/modules/pathkit/perf/effects.bench.js
@@ -1,20 +1,4 @@
-
-
describe('PathKit\'s Effects', function() {
- // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
- var PathKit = null;
- const LoadPathKit = new Promise(function(resolve, reject) {
- if (PathKit) {
- resolve();
- } else {
- PathKitInit({
- locateFile: (file) => '/pathkit/'+file,
- }).ready().then((_PathKit) => {
- PathKit = _PathKit;
- resolve();
- });
- }
- });
// see https://fiddle.skia.org/c/@discrete_path
function drawStar(X=128, Y=128, R=116) {
diff --git a/modules/pathkit/perf/path.bench.js b/modules/pathkit/perf/path.bench.js
index d8dc47e..01fd6f9 100644
--- a/modules/pathkit/perf/path.bench.js
+++ b/modules/pathkit/perf/path.bench.js
@@ -1,21 +1,4 @@
-
-
describe('PathKit\'s Path Behavior', function() {
- // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
- var PathKit = null;
- const LoadPathKit = new Promise(function(resolve, reject) {
- if (PathKit) {
- resolve();
- } else {
- PathKitInit({
- locateFile: (file) => '/pathkit/'+file,
- }).ready().then((_PathKit) => {
- PathKit = _PathKit;
- resolve();
- });
- }
- });
-
function drawPath() {
let path = PathKit.NewPath();
path.moveTo(20, 5);
diff --git a/modules/pathkit/perf/pathops.bench.js b/modules/pathkit/perf/pathops.bench.js
index aa105a4..31d7e05 100644
--- a/modules/pathkit/perf/pathops.bench.js
+++ b/modules/pathkit/perf/pathops.bench.js
@@ -1,21 +1,4 @@
-
-
describe('PathKit\'s Pathops', function() {
- // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
- var PathKit = null;
- const LoadPathKit = new Promise(function(resolve, reject) {
- if (PathKit) {
- resolve();
- } else {
- PathKitInit({
- locateFile: (file) => '/pathkit/'+file,
- }).ready().then((_PathKit) => {
- PathKit = _PathKit;
- resolve();
- });
- }
- });
-
// see https://fiddle.skia.org/c/@discrete_path
function drawStar(X=128, Y=128, R=116) {
let p = PathKit.NewPath();
diff --git a/modules/pathkit/perf/perfReporter.js b/modules/pathkit/perf/perfReporter.js
index d74110c..c60cfbc 100644
--- a/modules/pathkit/perf/perfReporter.js
+++ b/modules/pathkit/perf/perfReporter.js
@@ -3,47 +3,52 @@
// Typically used for debugging.
const fail_on_no_perf = false;
-
function benchmarkAndReport(benchName, setupFn, testFn, teardownFn) {
- let ctx = {};
- // warmup 3 times (arbitrary choice)
- setupFn(ctx);
- testFn(ctx);
- testFn(ctx);
- testFn(ctx);
- teardownFn(ctx);
-
- ctx = {};
- setupFn(ctx);
- let start = Date.now();
- let now = start;
- times = 0;
- // See how many times we can do it in 100ms (arbitrary choice)
- while (now - start < 100) {
+ try {
+ let ctx = {};
+ // warmup 3 times (arbitrary choice)
+ setupFn(ctx);
testFn(ctx);
- now = Date.now();
- times++;
- }
-
- teardownFn(ctx);
-
- // Try to make it go for 2 seconds (arbitrarily chosen)
- // Since the pre-try took 100ms, multiply by 20 to get
- // approximate tries in 2s
- let goalTimes = times * 20;
- setupFn(ctx);
- start = Date.now();
- times = 0;
- while (times < goalTimes) {
testFn(ctx);
- times++;
- }
- let end = Date.now();
- teardownFn(ctx);
+ testFn(ctx);
+ teardownFn(ctx);
- let us = (end - start) * 1000 / times;
- console.log(benchName, `${us} microseconds`)
- return _report(us, benchName);
+ ctx = {};
+ setupFn(ctx);
+ let start = Date.now();
+ let now = start;
+ times = 0;
+ // See how many times we can do it in 100ms (arbitrary choice)
+ while (now - start < 100) {
+ testFn(ctx);
+ now = Date.now();
+ times++;
+ }
+
+ teardownFn(ctx);
+
+ // Try to make it go for 2 seconds (arbitrarily chosen)
+ // Since the pre-try took 100ms, multiply by 20 to get
+ // approximate tries in 2s (unless now - start >> 100 ms)
+ let goalTimes = times * 20;
+ ctx = {};
+ setupFn(ctx);
+ times = 0;
+ start = Date.now();
+ while (times < goalTimes) {
+ testFn(ctx);
+ times++;
+ }
+ const end = Date.now();
+ teardownFn(ctx);
+
+ const us = (end - start) * 1000 / times;
+ console.log(benchName, `${us} microseconds`)
+ return _report(us, benchName);
+ } catch(e) {
+ console.error('caught error', e);
+ return Promise.reject(e);
+ }
}