Edited browser benchmark to report memory use per #813 (#817)

master
Balearica 1 year ago committed by GitHub
parent bb973ea2b8
commit d0df3d126c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      benchmarks/browser/speed-benchmark.html
  2. 10
      scripts/server.js

@ -16,7 +16,18 @@
const worker = await createWorker();
await worker.loadLanguage('eng');
await worker.initialize('eng');
// The performance.measureUserAgentSpecificMemory function only runs under specific circumstances for security reasons.
// See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/measureUserAgentSpecificMemory#security_requirements
// Launching a server using `npm start` and accessing via localhost on the same system should meet these conditions.
const debugMemory = true;
if (debugMemory && crossOriginIsolated) {
console.log("Memory utilization after initialization:");
console.log(await performance.measureUserAgentSpecificMemory());
} else {
console.log("Unable to run `performance.measureUserAgentSpecificMemory`: not crossOriginIsolated.")
}
const fileArr = ["../data/meditations.jpg", "../data/tyger.jpg", "../data/testocr.png"];
let timeTotal = 0;
for (let file of fileArr) {
@ -29,6 +40,12 @@
timeTotal += timeDif;
document.getElementById('message').innerHTML += "\n" + file + " [x10] runtime: " + timeDif + "s";
}
if (debugMemory && crossOriginIsolated) {
console.log("Memory utilization after recognition:");
console.log(await performance.measureUserAgentSpecificMemory());
}
document.getElementById('message').innerHTML += "\nTotal runtime: " + timeTotal + "s";
})();

@ -9,9 +9,17 @@ const compiler = webpack(webpackConfig);
const app = express();
app.use(cors());
app.use('/', express.static(path.resolve(__dirname, '..')));
app.use(middleware(compiler, { publicPath: '/dist', writeToDisk: true }));
// These headers are required to measure memory within the benchmark code.
// If they are problematic within other contexts they can be removed.
app.use(express.static(path.resolve(__dirname, '..'), {
setHeaders: (res) => {
res.set('Cross-Origin-Opener-Policy', 'same-origin');
res.set('Cross-Origin-Embedder-Policy', 'require-corp');
}
}));
module.exports = app.listen(3000, () => {
console.log('Server is running on the port no. 3000');
});

Loading…
Cancel
Save