-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework deep value reading (#6)
Introduces our own deep value function we can easier optimise. Also adds a bunch of tests and updates some dev dependencies/benchmarks.
- Loading branch information
Showing
8 changed files
with
779 additions
and
163 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 |
---|---|---|
@@ -1,28 +1,112 @@ | ||
import {Bench} from 'tinybench'; | ||
import {parse} from '../lib/main.js'; | ||
import {parse as fastParse} from 'fast-querystring'; | ||
import {parse as qsParse} from 'qs'; | ||
|
||
const inputs = [ | ||
'foo=123&bar=456', | ||
'foo[bar]=123&baz=456', | ||
'foo=123&bar=456&foo=123', | ||
'foo[bar][baz]=woof' | ||
]; | ||
const bench = new Bench(); | ||
|
||
bench | ||
.add('picoquery (parse)', () => { | ||
for (const input of inputs) { | ||
parse(input); | ||
const suites = [ | ||
{ | ||
name: 'Basic (no nesting)', | ||
inputs: [ | ||
'foo=bar', | ||
'foo=123&bar=456', | ||
'foo.bar=123&baz=456', | ||
'foo=123&bar=456&foo=123', | ||
'foo.bar.baz=woof' | ||
], | ||
options: { | ||
qs: {allowDots: false}, | ||
pico: {nested: false} | ||
} | ||
}, | ||
{ | ||
name: 'Dot-syntax nesting', | ||
inputs: [ | ||
'foo=bar', | ||
'foo=123&bar=456', | ||
'foo.bar=123&baz=456', | ||
'foo.bar.baz=woof' | ||
], | ||
options: { | ||
qs: {allowDots: true}, | ||
pico: {nested: true} | ||
} | ||
}, | ||
{ | ||
name: 'Index-syntax nesting', | ||
inputs: [ | ||
'foo=bar', | ||
'foo=bar&bar=baz', | ||
'foo[bar]=baz', | ||
'some[deeply][nested][key]=value', | ||
'foo[foo]=a&bar[bar]=b' | ||
], | ||
options: { | ||
qs: {allowDots: false}, | ||
pico: {nested: true, nestingSyntax: 'index'} | ||
} | ||
}, | ||
{ | ||
name: 'Custom delimiter', | ||
inputs: [ | ||
'foo=a;bar=b', | ||
'foo=a', | ||
'foo=a;bar=b;baz=c' | ||
], | ||
options: { | ||
qs: {delimiter: ';'}, | ||
pico: {nested: false, delimiter: ';'} | ||
} | ||
}, | ||
{ | ||
name: 'Bracket-style arrays', | ||
inputs: [ | ||
'foo[]=a&foo[]=b', | ||
'foo=a&bar[]=b&baz=c&bar[]=b', | ||
'foo=bar' | ||
], | ||
options: { | ||
pico: {arrayRepeat: true, arrayRepeatSyntax: 'bracket'} | ||
} | ||
}) | ||
.add('fast-querystring (no nesting)', () => { | ||
for (const input of inputs) { | ||
fastParse(input); | ||
}, | ||
{ | ||
name: 'Repeat-style arrays', | ||
inputs: [ | ||
'foo=a&foo=b', | ||
'foo=a&bar=b&baz=c&bar=b', | ||
'foo=bar' | ||
], | ||
options: { | ||
pico: {arrayRepeat: true, arrayRepeatSyntax: 'repeat'} | ||
} | ||
}); | ||
} | ||
]; | ||
|
||
for (const suite of suites) { | ||
const bench = new Bench(); | ||
|
||
bench | ||
.add('picoquery', () => { | ||
for (const input of suite.inputs) { | ||
parse(input, suite.options?.pico); | ||
} | ||
}) | ||
.add('qs', () => { | ||
for (const input of suite.inputs) { | ||
qsParse(input, suite.options?.qs); | ||
} | ||
}) | ||
.add('fast-querystring (no nesting)', () => { | ||
for (const input of suite.inputs) { | ||
fastParse(input); | ||
} | ||
}); | ||
|
||
console.log('Benchmark:', suite.name); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
console.table(bench.table()); | ||
} | ||
|
||
console.table(bench.table()); | ||
setInterval(() => {}, 5000); |
Oops, something went wrong.