-
-
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.
Adds the stringify function and updates benchmarks.
- Loading branch information
Showing
13 changed files
with
786 additions
and
254 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
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,107 @@ | ||
import {Bench} from 'tinybench'; | ||
import {stringify} from '../lib/main.js'; | ||
import {stringify as fastStringify} from 'fast-querystring'; | ||
import {stringify as qsStringify} from 'qs'; | ||
|
||
const suites = [ | ||
{ | ||
name: 'Basic (no nesting)', | ||
inputs: [ | ||
{foo: 'x', bar: 'y', baz: 'z'} | ||
], | ||
options: { | ||
qs: {allowDots: false}, | ||
pico: {nested: false} | ||
} | ||
}, | ||
{ | ||
name: 'Dot-syntax nesting', | ||
inputs: [ | ||
{ | ||
foo: { | ||
bar0: 'x', | ||
bar1: { | ||
baz0: 'y', | ||
baz1: 'z' | ||
} | ||
} | ||
} | ||
], | ||
options: { | ||
qs: {allowDots: true}, | ||
pico: {nested: true} | ||
} | ||
}, | ||
{ | ||
name: 'Index-syntax nesting', | ||
inputs: [ | ||
{ | ||
foo: { | ||
bar0: 'x', | ||
bar1: { | ||
baz0: 'y', | ||
baz1: 'z' | ||
} | ||
} | ||
} | ||
], | ||
options: { | ||
qs: {allowDots: false}, | ||
pico: {nested: true, nestingSyntax: 'index'} | ||
} | ||
}, | ||
{ | ||
name: 'Custom delimiter', | ||
inputs: [{foo: 'a', bar: 'b', baz: 'c'}], | ||
options: { | ||
qs: {delimiter: ';'}, | ||
pico: {nested: false, delimiter: ';'} | ||
} | ||
}, | ||
{ | ||
name: 'Bracket-style arrays', | ||
inputs: [ | ||
{foo: ['a', 'b', 'c'], bar: 'y'} | ||
], | ||
options: { | ||
pico: {arrayRepeat: true, arrayRepeatSyntax: 'bracket'} | ||
} | ||
}, | ||
{ | ||
name: 'Repeat-style arrays', | ||
inputs: [ | ||
{foo: ['a', 'b', 'c'], bar: 'y'} | ||
], | ||
options: { | ||
pico: {arrayRepeat: true, arrayRepeatSyntax: 'repeat'} | ||
} | ||
} | ||
]; | ||
|
||
for (const suite of suites) { | ||
const bench = new Bench(); | ||
|
||
bench | ||
.add('picoquery', () => { | ||
for (const input of suite.inputs) { | ||
stringify(input, suite.options?.pico); | ||
} | ||
}) | ||
.add('qs', () => { | ||
for (const input of suite.inputs) { | ||
qsStringify(input, suite.options?.qs); | ||
} | ||
}) | ||
.add('fast-querystring (no nesting)', () => { | ||
for (const input of suite.inputs) { | ||
fastStringify(input); | ||
} | ||
}); | ||
|
||
console.log('Benchmark:', suite.name); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.table(bench.table()); | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export {parse} from './parse.js'; | ||
export {stringify} from './stringify.js'; |
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
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
Oops, something went wrong.