Skip to content

Commit

Permalink
More benchmark fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Jan 2, 2023
1 parent cf09b72 commit 118e424
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
17 changes: 12 additions & 5 deletions benchmarks/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<script type="importmap">
{
"imports": {
"@msgpack/msgpack": "/node_modules/@msgpack/msgpack/dist.es5+esm/index.mjs"
}
}
</script>
<script type="module">
let currentGroups = [document.body];

Expand All @@ -21,17 +28,17 @@
let origLog = console.log;
console.log = (...args) => {
origLog(...args);
let div = document.createElement('div');
div.textContent = args.join(' ');
let div = document.createElement('div');
div.textContent = args.join(' ');
currentGroups[0].append(div);
};

let origError = console.error;
console.error = (...args) => {
origError(...args);
let div = document.createElement('div');
div.textContent = args.join(' ');
div.style.color = 'red';
let div = document.createElement('div');
div.textContent = args.join(' ');
div.style.color = 'red';
currentGroups[0].append(div);
};
</script>
Expand Down
18 changes: 11 additions & 7 deletions benchmarks/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ let suiteOps = {
serialize: {}
};

const libs = await Promise.all(
['serde-wasm-bindgen', 'serde-json', 'serde-wasm-bindgen-reftypes']
.map(async dir => {
const libs = (
await Promise.all(
[
'serde-wasm-bindgen',
'serde-json',
'serde-wasm-bindgen-reftypes',
'msgpack'
].map(async dir => {
try {
const impl = await import(`./pkg/${dir}/serde_wasm_bindgen_benches.js`);
await impl.default(); // Init Wasm
Expand All @@ -17,11 +22,10 @@ const libs = await Promise.all(
return null;
}
})
.filter(Boolean)
);
)
).filter(Boolean);

let readFile,
filter;
let readFile, filter;

const isNode = typeof process !== 'undefined';

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:swb-reftypes": "cross-env RUSTFLAGS=\"-C target-feature=+reference-types\" WASM_BINDGEN_EXTERNREF=1 wasm-pack build -t web --out-dir pkg/serde-wasm-bindgen-reftypes -- --features serde-wasm-bindgen",
"build:json": "wasm-pack build -t web --out-dir pkg/serde-json -- --features serde-json",
"build:msgpack": "wasm-pack build -t web --out-dir pkg/msgpack -- --features msgpack",
"build": "npm run build:swb && npm run build:swb-reftypes && npm run build:json",
"build": "npm run build:swb && npm run build:json",
"test": "node index.mjs"
}
}
10 changes: 10 additions & 0 deletions benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ serde_impl!(|input| {

"msgpack" => {
parse: {
#[wasm_bindgen(module = "@msgpack/msgpack")]
extern "C" {
fn encode(input: &JsValue) -> Vec<u8>;
}

let input = encode(&input);
rmp_serde::from_slice(&input).unwrap_throw()
},

serialize: {
#[wasm_bindgen(module = "@msgpack/msgpack")]
extern "C" {
fn decode(input: &[u8]) -> JsValue;
}

let input = rmp_serde::to_vec(input).unwrap_throw();
decode(&input)
},
Expand Down

0 comments on commit 118e424

Please sign in to comment.