diff --git a/src/emulator/benchmark/bench.wasm b/src/emulator/benchmark/bench.wasm new file mode 100644 index 00000000..f9fb504a Binary files /dev/null and b/src/emulator/benchmark/bench.wasm differ diff --git a/src/emulator/benchmark/bench.wat b/src/emulator/benchmark/bench.wat new file mode 100644 index 00000000..9148976c --- /dev/null +++ b/src/emulator/benchmark/bench.wat @@ -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 + ) + ) +) diff --git a/src/emulator/package.json b/src/emulator/package.json index 864649da..250c9763 100644 --- a/src/emulator/package.json +++ b/src/emulator/package.json @@ -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" } } diff --git a/src/emulator/src/main.js b/src/emulator/src/main.js index 930eb00b..bbdbd86a 100644 --- a/src/emulator/src/main.js +++ b/src/emulator/src/main.js @@ -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) {} diff --git a/src/emulator/webpack.config.js b/src/emulator/webpack.config.js index 6dee8961..feeb4b63 100644 --- a/src/emulator/webpack.config.js +++ b/src/emulator/webpack.config.js @@ -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' } + ] + }) ] };