-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a3a506
commit 890ea5e
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import parseBenchmarks from './parse.bench.js' | ||
// import formatBenchmarks from './parse.bench.js' | ||
|
||
await parseBenchmarks() | ||
// await formatBenchmarks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { add, cycle, /* save, */ suite } from 'benny' | ||
import parse from './parse.js' // 'csv-rex/parse' | ||
|
||
const inputs = {} | ||
const configs = [] | ||
const baseline = { | ||
columns: 10, | ||
rows: 1_000, | ||
quotes: false, | ||
newlineChar: '\r\n', | ||
delimiterChar: ',', | ||
header: false, | ||
commentPrefixValue: false | ||
} | ||
configs.push({ ...baseline }) | ||
// expected to be slower, compare against each other | ||
configs.push({ ...baseline, columns: 100 }) // input has move columns | ||
configs.push({ ...baseline, rows: 10_000 }) // input has more rows | ||
// Options | ||
configs.push({ | ||
...baseline, | ||
header: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] | ||
}) // pre-defined headers to make object | ||
configs.push({ ...baseline, header: true }) // use header to make object | ||
configs.push({ ...baseline, newlineChar: '\n' }) // shorter newline ** should be fastest | ||
configs.push({ ...baseline, newlineChar: '' }) // detect newline | ||
configs.push({ ...baseline, delimiterChar: '\t' }) // detect delimiter | ||
configs.push({ ...baseline, delimiterChar: '' }) // detect delimiter | ||
configs.push({ ...baseline, commentPrefixValue: '//' }) // detect comments | ||
configs.push({ ...baseline, quotes: true }) // input has quoted fields | ||
|
||
configs.push({ ...baseline, newlineChar: '\n', delimiterChar: '\t' }) // TSV | ||
configs.push({ ...baseline }) | ||
|
||
const baselineDiff = (config) => { | ||
const diff = {} | ||
for (const key in config) { | ||
if (config[key] !== baseline[key]) { | ||
diff[key] = config[key] | ||
} | ||
} | ||
return diff | ||
} | ||
|
||
const testBatch = (configs) => { | ||
return configs.map((config) => { | ||
const { columns, rows, quotes, ...options } = config | ||
const delimiterChar = options.delimiterChar || baseline.delimiterChar | ||
const newlineChar = options.newlineChar || baseline.newlineChar | ||
const input = `${columns}x${rows} w/${ | ||
quotes ? '' : 'o' | ||
} quotes and {newlineChar:${newlineChar},delimiterChar:${delimiterChar}}` | ||
if (!inputs[input]) { | ||
const wrapper = quotes ? '"' : '' | ||
const delimiter = quotes ? `"${delimiterChar}"` : `${delimiterChar}` | ||
let csv = | ||
wrapper + | ||
Array.from({ length: columns + 1 }, (_, x) => `__${x}__`).join( | ||
delimiter | ||
) + | ||
wrapper + | ||
newlineChar | ||
for (let y = 0; y < rows; y++) { | ||
csv += | ||
wrapper + | ||
Array.from({ length: columns + 1 }, (_, x) => `${x}x${y}`).join( | ||
delimiter | ||
) + | ||
wrapper + | ||
newlineChar | ||
} | ||
inputs[input] = csv | ||
} | ||
return add( | ||
`parse(${JSON.stringify({ columns, rows, quotes })}, ${JSON.stringify( | ||
options | ||
)}) :: ${JSON.stringify(baselineDiff(config))}`, | ||
() => { | ||
parse(inputs[input], options) | ||
} | ||
) | ||
}) | ||
} | ||
|
||
const parseSuite = suite( | ||
'parse', | ||
...testBatch(configs), | ||
cycle() | ||
// save({file: 'parse.bench.csv', format: 'csv'}) | ||
) | ||
|
||
export default () => parseSuite |