Skip to content

Commit

Permalink
Edited browser benchmark to report memory use per #813
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Aug 28, 2023
1 parent bb973ea commit e00d334
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 18 additions & 1 deletion benchmarks/browser/speed-benchmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";

})();
Expand Down
10 changes: 9 additions & 1 deletion scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit e00d334

Please sign in to comment.