Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
Loading