Skip to content

Commit

Permalink
build: only build wasm on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Jun 3, 2020
1 parent 63bf7c5 commit fe1ed62
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ os:
- osx
- linux
before_install:
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash
- '[[ $TRAVIS_OS_NAME == linux ]] && docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten-slim:sdk-incoming-64bit bash'
before_script:
- npm run build:wasm
- '[[ $TRAVIS_OS_NAME == linux ]] && docker exec -it emscripten npm run build:wasm'
before_deploy:
- ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
- npm run prebuild
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"eslint-plugin-json": "^2.1.0",
"eslint-plugin-package-json": "^0.1.4",
"eslint-plugin-prettier": "^3.1.2",
"is-ci": "^2.0.0",
"jest": "^25.1.0",
"jscheck": "^0.2.0",
"node-addon-api": "^2.0.0",
Expand Down
35 changes: 28 additions & 7 deletions test/test.random.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const isCI = require('is-ci');
const JSC = require('jscheck');
const natural = require('../damerau-levenshtein.natural');
const native = require('../damerau-levenshtein.native');
const wasm = require('../damerau-levenshtein.wasm');
/** @type {typeof import('../damerau-levenshtein.wasm')} */
let wasm;
try {
wasm = require('../damerau-levenshtein.wasm');
} catch (err) {
console.warn('Failed to load wasm:', err);
}

const opts = [];
for (const insertion_cost of [0.5, 1]) {
Expand Down Expand Up @@ -59,12 +66,14 @@ afterAll(() => {
'\n Overall:',
(totalNaturalTime / totalNapiTime).toFixed(1)
);
console.log(
'Wasm speedup:\n Mean:',
(totalWasmFactors / wasmSpeedupFactors.length).toFixed(1),
'\n Overall:',
(totalNaturalTime / totalWasmTime).toFixed(1)
);
if (wasm) {
console.log(
'Wasm speedup:\n Mean:',
(totalWasmFactors / wasmSpeedupFactors.length).toFixed(1),
'\n Overall:',
(totalNaturalTime / totalWasmTime).toFixed(1)
);
}

if (mismatches.length > 0) {
console.error('Failing options:', mismatches);
Expand Down Expand Up @@ -140,6 +149,18 @@ for (const options of opts) {
expect(factor).toBeGreaterThan(2);
});

if (!wasm) {
if (isCI && process.platform === 'darwin') {
it.todo('should generate correct distances with wasm code');
} else {
it('should generate correct distances with wasm code', (done) => {
done.fail('wasm did not load');
});
}
it.todo('should be faster than natural in wasm mode');
return;
}

let wasmTime;
it(
'should generate correct distances with wasm code',
Expand Down

0 comments on commit fe1ed62

Please sign in to comment.