Skip to content

Commit

Permalink
feat: rework deep value reading (#6)
Browse files Browse the repository at this point in the history
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
43081j authored Jun 21, 2024
1 parent 8fb8e72 commit 0131bb5
Show file tree
Hide file tree
Showing 8 changed files with 779 additions and 163 deletions.
124 changes: 104 additions & 20 deletions bench/main.js
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);
Loading

0 comments on commit 0131bb5

Please sign in to comment.