mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 06:00:21 +08:00
dev: add wasm bench
This commit is contained in:
parent
fff8993200
commit
d0535cf10b
BIN
src/emulator/benchmark/bench.wasm
Normal file
BIN
src/emulator/benchmark/bench.wasm
Normal file
Binary file not shown.
10
src/emulator/benchmark/bench.wat
Normal file
10
src/emulator/benchmark/bench.wat
Normal 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
|
||||
)
|
||||
)
|
||||
)
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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) {}
|
||||
|
@ -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' }
|
||||
]
|
||||
})
|
||||
]
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user