Skip to content

Commit

Permalink
chore: Improve test (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajendrant authored Sep 3, 2020
1 parent 2cd574b commit 634fbe4
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 176 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ os:
- osx
- linux
- windows
dist: xenial
after_script:
- npm run benchmark
before_deploy:
Expand All @@ -33,5 +32,3 @@ deploy:
tags: true
node: node
api_key: $GITHUB_TOKEN
after_deploy:
- npm run benchmark
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ platform:

install:
- SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin;%PATH%
- ps: Install-Product node $env:nodejs_version x64
- ps: Install-Product node $env:nodejs_version $env:platform
- node --version
- npm --version
- npm install

test_script:
- node --version
- npm --version
- npm test

after_test:
Expand Down
90 changes: 0 additions & 90 deletions benchmark/benchmark-large.coffee

This file was deleted.

147 changes: 147 additions & 0 deletions benchmark/benchmark-large.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
require('coffeescript/register')
const fs = require('fs')
const path = require('path')
const testutils = require('./testutils')

const FuzzaldrinPlusFast = require('../fuzzaldrin-dist')
const legacy = require('fuzzaldrin-plus')

const lines = fs.readFileSync(path.join(__dirname, 'data-large.txt'), 'utf8').trim().split('\n')
const dict = lines.map((item) => {
return {
key: item,
val: item
}
})

const fuzzaldrinplusfast = FuzzaldrinPlusFast.New()
fuzzaldrinplusfast.setCandidates(lines)

const two_letter_tests = [
'dp', 'la', 'ow', 'rb', 'dg', 'by', 'pf', 'fk', 'qk', 'pu',
'cl', 'cu', 'cj', 'dz', 'mh', 'sm', 'qk', 'cz', 'nf', 'rb'
]
const three_letter_tests = [
'mxl', 'ipe', 'dvi', 'sxg', 'qiu', 'mvw', 'efa', 'utz', 'pxr', 'dsr',
'inw', 'xck', 'bqk', 'ibv', 'zbh', 'ozj', 'wht', 'kny', 'ccj', 'dtv'
]


console.time('TwoLetter#legacy')
for (const query of two_letter_tests)
legacy.filter(lines, query, {
maxResults: 10
})
console.timeEnd('TwoLetter#legacy')

console.time('TwoLetter#fuzzaldrin-plus-fast#DirectFilter')
for (const query of two_letter_tests)
FuzzaldrinPlusFast.filter(lines, query, {
maxResults: 10
})
console.timeEnd('TwoLetter#fuzzaldrin-plus-fast#DirectFilter')

console.time('TwoLetter#fuzzaldrin-plus-fast#setCandidates#filter')
for (const query of two_letter_tests)
fuzzaldrinplusfast.filter(query, {
maxResults: 10
})
console.timeEnd('TwoLetter#fuzzaldrin-plus-fast#setCandidates#filter')
console.log("======")


console.time('ThreeLetter#legacy')
for (const query of three_letter_tests)
legacy.filter(lines, query, {
maxResults: 10
})
console.timeEnd('ThreeLetter#legacy')

console.time('ThreeLetter#fuzzaldrin-plus-fast#DirectFilter')
for (const query of three_letter_tests)
FuzzaldrinPlusFast.filter(lines, query, {
maxResults: 10
})
console.timeEnd('ThreeLetter#fuzzaldrin-plus-fast#DirectFilter')

console.time('ThreeLetter#fuzzaldrin-plus-fast#setCandidates#filter')
for (const query of three_letter_tests)
fuzzaldrinplusfast.filter(query, {
maxResults: 10
})
console.timeEnd('ThreeLetter#fuzzaldrin-plus-fast#setCandidates#filter')
console.log("======")

console.time('TwoLetter#Keybased#Filter')
for (const query of two_letter_tests)
FuzzaldrinPlusFast.filter(dict, query, {
maxResults: 10,
key: 'key'
})
console.timeEnd('TwoLetter#Keybased#Filter')
console.log("======")


console.time('setCandidates')
let obj = FuzzaldrinPlusFast.New()
obj.setCandidates(lines)
console.timeEnd('setCandidates')

console.time('TwoLetter#Filter')
for (const query of two_letter_tests)
obj.filter(query, {
maxResults: 10
})
console.timeEnd('TwoLetter#Filter')

console.time('ThreeLetter#Filter')
for (const query of three_letter_tests)
obj.filter(query, {
maxResults: 10
})
console.timeEnd('ThreeLetter#Filter')
console.log("======")


console.time('setCandidates#Keybased')
obj = FuzzaldrinPlusFast.New()
obj.setCandidates(dict, {
key: 'key'
})
console.timeEnd('setCandidates#Keybased')

console.time('TwoLetter#Keybased#Filter')
for (const query of two_letter_tests)
obj.filter(query, {
maxResults: 10,
key: 'key'
})
console.timeEnd('TwoLetter#Keybased#Filter')

console.time('ThreeLetter#Keybased#Filter')
for (const query of three_letter_tests)
obj.filter(query, {
maxResults: 10,
key: 'key'
})
console.timeEnd('ThreeLetter#Keybased#Filter')


// An exmaple run below
// TwoLetter#legacy: 20466.854ms
// TwoLetter#fuzzaldrin-plus-fast#DirectFilter: 3362.571ms
// TwoLetter#fuzzaldrin-plus-fast#setCandidates#filter: 610.414ms
// ======
// ThreeLetter#legacy: 15753.575ms
// ThreeLetter#fuzzaldrin-plus-fast#DirectFilter: 3422.584ms
// ThreeLetter#fuzzaldrin-plus-fast#setCandidates#filter: 619.298ms
// ======
// TwoLetter#Keybased#Filter: 4620.753ms
// ======
// setCandidates: 127.881ms
// TwoLetter#Filter: 611.596ms
// ThreeLetter#Filter: 618.661ms
// ======
// setCandidates#Keybased: 176.712ms
// TwoLetter#Keybased#Filter: 621.859ms
// ThreeLetter#Keybased#Filter: 649.107ms
46 changes: 12 additions & 34 deletions benchmark/benchmark-small.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require('coffeescript/register')
const fs = require('fs')
const path = require('path')

const performance = (require('perf_hooks')).performance
const testutils = require('./testutils')

const fuzzaldrinPlus = require('../fuzzaldrin-dist')
const legacy = require('fuzzaldrin-plus')
Expand All @@ -19,36 +18,15 @@ const mitigation = {
fuzzaldrinPlus.filter(lines, 'index', forceAllMatch)
legacy.filter(lines, 'index')

function doFilterTest(query) {
console.log(`====== Running test - query:${query} ======`)
let startTime = performance.now()
const res_actual = fuzzaldrinPlus.filter(lines, query)
const elapsed = Math.round(performance.now() - startTime)

startTime = performance.now()
const res_expected = legacy.filter(lines, query)
const elapsed_legacy = Math.round(performance.now() - startTime)

if (res_actual.length != res_expected.length) {
console.error("Results count changed! #{results.length} instead of #{results_legacy.length}")
process.exit(1)
}

console.log(`Elapsed time - fuzzaldrin-plus-fast: ${elapsed} ms vs. fuzzaldrin-plus: ${elapsed_legacy} ms`)
if (elapsed > elapsed_legacy) {
console.error(`====== fuzzaldrin-plus-fast is SLOWER`)
}
console.log('')
}

doFilterTest('nm')
doFilterTest('npm')
doFilterTest('node')
doFilterTest('grunt')
doFilterTest('html')
doFilterTest('doc')
doFilterTest('cli')
doFilterTest('js')
doFilterTest('jas')
doFilterTest('mine')
doFilterTest('stream')
testutils.doFilterTest(null, lines, 'nm')
testutils.doFilterTest(null, lines, 'npm')
testutils.doFilterTest(null, lines, 'node')
testutils.doFilterTest(null, lines, 'grunt')
testutils.doFilterTest(null, lines, 'html')
testutils.doFilterTest(null, lines, 'doc')
testutils.doFilterTest(null, lines, 'cli')
testutils.doFilterTest(null, lines, 'js')
testutils.doFilterTest(null, lines, 'jas')
testutils.doFilterTest(null, lines, 'mine')
testutils.doFilterTest(null, lines, 'stream')
Loading

0 comments on commit 634fbe4

Please sign in to comment.