Skip to content

Commit

Permalink
add matching node.js test of harden/branding-mode performance
Browse files Browse the repository at this point in the history
and results from my linux box
  • Loading branch information
warner committed May 18, 2021
1 parent b7a0586 commit 2cde3a7
Show file tree
Hide file tree
Showing 8 changed files with 2,601 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/xsnap/harden-perf-node/data.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
turing-node-data.json was captured on my local linux box named 'turing',
whose /proc/cpuinfo says:

model name : Intel(R) Xeon(R) CPU E3-1230L v3 @ 1.80GHz

by running './drive-node-perf.sh > data.json' and then lightly editing
data.json to add [] and remove a trailing comma.

-Brian Warner, 18-may-2021
10 changes: 10 additions & 0 deletions packages/xsnap/harden-perf-node/drive-node-perf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

for name in nothing list hardList listHard; do
for branding in BOTH POSITIVE NEGATIVE; do
# 'listHard' is the most time consuming, 10000 takes 90s
for count in 10 100 1000 10000; do
node -r esm ./t-node-perf.js $branding $name $count |grep -v "Removing"
done
done
done
49 changes: 49 additions & 0 deletions packages/xsnap/harden-perf-node/t-node-perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { branding, name, count } from './t-setup.js';
import { performance } from 'perf_hooks';

function f(count, body, post) {
const before = performance.now();
let list = {};
for (let i = 0; i < count; i++) {
if (body === '//nothing') {
//nothing
} else if (body === 'list = {next: list};') {
list = {next: list};
} else if (body === 'list = harden({next: list});') {
list = harden({next: list});
} else {
throw Error(`unknown body '${body}'`);
}
}
if (post === '//nothing') {
// nothing
} else if (post === 'harden(list);') {
harden(list);
} else {
throw Error(`unknown post '${post}'`);
}
const after = performance.now();
return(after - before);
}

const [body, post] = {
nothing: ['//nothing', '//nothing'],
list: ['list = {next: list};', '//nothing'],
listHard: ['list = harden({next: list});', '//nothing'],
hardList: ['list = {next: list};', 'harden(list);'],
}[name];

const title = `time, ${branding}, ${count}, ${name}`;
try {
const innerTime = f(count, body, post);
const record = {
branding,
count,
name,
innerTime,
};
console.log(JSON.stringify(record, undefined, ' '), '\n,\n');
} catch (e) {
console.log(`error`, e);
process.exit(1);
}
9 changes: 9 additions & 0 deletions packages/xsnap/harden-perf-node/t-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'ses';

const argv = process.argv.splice(2);
const [branding, name, count_s] = argv;
const count = Number(count_s);
globalThis.HARDEN_BRANDING = branding;
lockdown({});

export { branding, name, count };
Loading

0 comments on commit 2cde3a7

Please sign in to comment.