dev: add wasm bench

This commit is contained in:
KernelDeimos 2024-09-25 21:45:03 -04:00
parent fff8993200
commit d0535cf10b
5 changed files with 44 additions and 1 deletions

Binary file not shown.

View File

@ -0,0 +1,10 @@
(module
(func $benchmark (export "benchmark")
(local $i i32)
(loop $loop
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(i32.eq (local.get $i) (i32.const 10000))
br_if $loop
)
)
)

View File

@ -14,6 +14,7 @@
"html-webpack-plugin": "^5.6.0"
},
"dependencies": {
"brotli-dec-wasm": "^2.3.0"
"brotli-dec-wasm": "^2.3.0",
"copy-webpack-plugin": "^12.0.2"
}
}

View File

@ -114,8 +114,34 @@ puter.ui.on('connection', event => {
conn.on('message', pty_on_first_message);
});
const bench = async ({ modules }) => {
const { benchmark } = modules.bench;
const ts_start = performance.now();
benchmark();
const ts_end = performance.now();
// console.log('benchmark took', ts_end - ts_start);
return ts_end - ts_start;
}
const bench_20ms = async (ctx) => {
let ts = 0, count = 0;
for (;;) {
ts += await bench(ctx);
count++;
if ( ts > 20 ) {
return count;
}
}
}
window.onload = async function()
{
const modules = {};
modules.bench = (await WebAssembly.instantiateStreaming(
fetch('./static/bench.wasm'))).instance.exports;
const res = await bench_20ms({ modules });
console.log('result', res);
let emu_config; try {
emu_config = await puter.fs.read('config.json');
} catch (e) {}

View File

@ -1,5 +1,6 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DefinePlugin = require('webpack').DefinePlugin;
const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
entry: [
@ -12,5 +13,10 @@ module.exports = {
new DefinePlugin({
MODE: JSON.stringify(process.env.MODE ?? 'dev')
}),
new CopyPlugin({
patterns: [
{ from: 'benchmark', to: 'static' }
]
})
]
};