Fix and refactor bench scripts
This commit is contained in:
parent
719a464687
commit
49408299d2
|
@ -40,37 +40,6 @@ const fromEntries = entries => {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sizes = {};
|
|
||||||
const setSize = (program, test, result) => {
|
|
||||||
if (!sizes[test]) {
|
|
||||||
sizes[test] = {
|
|
||||||
original: {
|
|
||||||
absolute: tests.find(t => t.name === test).contentAsString.length,
|
|
||||||
relative: 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const original = sizes[test].original.absolute;
|
|
||||||
sizes[test][program] = {
|
|
||||||
absolute: result,
|
|
||||||
relative: result / original,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Run once to set sizes.
|
|
||||||
for (const t of tests) {
|
|
||||||
for (const m of Object.keys(minifiers)) {
|
|
||||||
try {
|
|
||||||
setSize(m, t.name, minifiers[m](t.contentAsString, t.contentAsBuffer).length);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`Failed to run ${m} on test ${t.name}:`);
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.writeSizeResults(sizes);
|
|
||||||
|
|
||||||
const runTest = test => new Promise((resolve, reject) => {
|
const runTest = test => new Promise((resolve, reject) => {
|
||||||
// Run JS libraries.
|
// Run JS libraries.
|
||||||
const suite = new benchmark.Suite();
|
const suite = new benchmark.Suite();
|
||||||
|
|
|
@ -4,16 +4,8 @@ set -e
|
||||||
|
|
||||||
pushd "$(dirname "$0")"
|
pushd "$(dirname "$0")"
|
||||||
|
|
||||||
nodejs_cargo_toml="../nodejs/native/Cargo.toml"
|
bash ../nodejs/build.sh
|
||||||
|
|
||||||
if [ -f "$nodejs_cargo_toml.orig" ]; then
|
|
||||||
echo 'Not altering Node.js Cargo.toml file'
|
|
||||||
else
|
|
||||||
cp "$nodejs_cargo_toml" "$nodejs_cargo_toml.orig"
|
|
||||||
fi
|
|
||||||
sed -i 's%^hyperbuild = .*$%hyperbuild = { path = "../.." }%' "$nodejs_cargo_toml"
|
|
||||||
HYPERBUILD_NODEJS_SKIP_BIN_DOWNLOAD=1 npm rebuild hyperbuild
|
|
||||||
mv "$nodejs_cargo_toml.orig" "$nodejs_cargo_toml"
|
|
||||||
pushd hyperbuild-bench
|
pushd hyperbuild-bench
|
||||||
cargo build --release
|
cargo build --release
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -3,7 +3,7 @@ const hyperbuild = require("hyperbuild");
|
||||||
const minimize = require("minimize");
|
const minimize = require("minimize");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'hyperbuild-nodejs': (_, buffer) => hyperbuild.minify_in_place(Buffer.from(buffer)),
|
'hyperbuild-nodejs': (_, buffer) => hyperbuild.minifyInPlace(Buffer.from(buffer)),
|
||||||
'html-minifier': content => htmlMinifier.minify(content, {
|
'html-minifier': content => htmlMinifier.minify(content, {
|
||||||
collapseBooleanAttributes: true,
|
collapseBooleanAttributes: true,
|
||||||
collapseInlineTagWhitespace: true,
|
collapseInlineTagWhitespace: true,
|
||||||
|
|
23
bench/run.js
23
bench/run.js
|
@ -2,14 +2,34 @@ const fs = require('fs');
|
||||||
const mkdirp = require('mkdirp');
|
const mkdirp = require('mkdirp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const minifiers = require('./minifiers');
|
const minifiers = require('./minifiers');
|
||||||
|
const results = require('./results');
|
||||||
const tests = require('./tests');
|
const tests = require('./tests');
|
||||||
|
|
||||||
|
const sizes = {};
|
||||||
|
const setSize = (program, test, result) => {
|
||||||
|
if (!sizes[test]) {
|
||||||
|
sizes[test] = {
|
||||||
|
original: {
|
||||||
|
absolute: tests.find(t => t.name === test).contentAsBuffer.length,
|
||||||
|
relative: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const original = sizes[test].original.absolute;
|
||||||
|
sizes[test][program] = {
|
||||||
|
absolute: result,
|
||||||
|
relative: result / original,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
for (const t of tests) {
|
for (const t of tests) {
|
||||||
for (const m of Object.keys(minifiers)) {
|
for (const m of Object.keys(minifiers)) {
|
||||||
try {
|
try {
|
||||||
|
const min = minifiers[m](t.contentAsString, t.contentAsBuffer);
|
||||||
|
setSize(m, t.name, min.length);
|
||||||
const minPath = path.join(__dirname, 'min', m, `${t.name}.html`);
|
const minPath = path.join(__dirname, 'min', m, `${t.name}.html`);
|
||||||
mkdirp.sync(path.dirname(minPath));
|
mkdirp.sync(path.dirname(minPath));
|
||||||
fs.writeFileSync(minPath, minifiers[m](t.contentAsString, t.contentAsBuffer));
|
fs.writeFileSync(minPath, min);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to run ${m} on test ${t.name}:`);
|
console.error(`Failed to run ${m} on test ${t.name}:`);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -17,3 +37,4 @@ for (const t of tests) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
results.writeSizeResults(sizes);
|
||||||
|
|
|
@ -39,8 +39,8 @@ if [ -f Cargo.toml.orig ]; then
|
||||||
echo 'Not altering Java Cargo.toml file'
|
echo 'Not altering Java Cargo.toml file'
|
||||||
else
|
else
|
||||||
cp Cargo.toml Cargo.toml.orig
|
cp Cargo.toml Cargo.toml.orig
|
||||||
|
sed -i 's%^hyperbuild = .*$%hyperbuild = { path = ".." }%' Cargo.toml
|
||||||
fi
|
fi
|
||||||
sed -i 's%^hyperbuild = .*$%hyperbuild = { path = ".." }%' Cargo.toml
|
|
||||||
cargo build $rust_build_arg
|
cargo build $rust_build_arg
|
||||||
mv Cargo.toml.orig Cargo.toml
|
mv Cargo.toml.orig Cargo.toml
|
||||||
cp target/rust/$rust_build_dir/libhyperbuild_java.$ext src/main/resources/$os_name-x86_64.nativelib
|
cp target/rust/$rust_build_dir/libhyperbuild_java.$ext src/main/resources/$os_name-x86_64.nativelib
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Builds hyperbuild-nodejs with native module for local testing.
|
||||||
|
# Built package will only run current platform and Node.js version.
|
||||||
|
|
||||||
|
pushd "$(dirname "$0")"
|
||||||
|
|
||||||
|
npm install
|
||||||
|
|
||||||
|
rm -rf dist
|
||||||
|
npx tsc
|
||||||
|
|
||||||
|
if [ -f native/Cargo.toml.orig ]; then
|
||||||
|
echo 'Not altering Node.js Cargo.toml file'
|
||||||
|
else
|
||||||
|
cp native/Cargo.toml native/Cargo.toml.orig
|
||||||
|
sed -i 's%^hyperbuild = .*$%hyperbuild = { path = "../.." }%' native/Cargo.toml
|
||||||
|
fi
|
||||||
|
npx neon build --release
|
||||||
|
mv native/Cargo.toml.orig native/Cargo.toml
|
||||||
|
|
||||||
|
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||||
|
os_name="linux"
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
os_name="macos"
|
||||||
|
elif [[ "$OSTYPE" == "cygwin" ]]; then
|
||||||
|
os_name="windows"
|
||||||
|
elif [[ "$OSTYPE" == "msys" ]]; then
|
||||||
|
os_name="windows"
|
||||||
|
elif [[ "$OSTYPE" == "win32" ]]; then
|
||||||
|
os_name="windows"
|
||||||
|
else
|
||||||
|
echo "Unknown OS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
node_version=$(node -e 'console.log(process.versions.node.split(".")[0])')
|
||||||
|
|
||||||
|
mv native/index.node "dist/$os_name-x86_64-node$node_version.node"
|
||||||
|
|
||||||
|
popd
|
Loading…
Reference in New Issue