mirror of
https://github.com/qntm/fastjson
synced 2026-03-14 09:34:41 +01:00
Compare commits
No commits in common. "d743846a53e6041598908038162906ef8d4c92e6" and "6578b5ebb42899c035018ad83af4d72416b57942" have entirely different histories.
d743846a53
...
6578b5ebb4
1
.gitignore
vendored
1
.gitignore
vendored
@ -45,4 +45,3 @@ Temporary Items
|
|||||||
# mine
|
# mine
|
||||||
coverage
|
coverage
|
||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
|
||||||
|
|||||||
@ -53,9 +53,6 @@ How this other representation should be constructed is not specified. The method
|
|||||||
|
|
||||||
Likewise, how such text should be generated from the input, or even whether any input should be accepted, is not specified. `fastjson.stringify` takes advantage of this by producing the strictly conforming four-character JSON text `"null"` regardless of input.
|
Likewise, how such text should be generated from the input, or even whether any input should be accepted, is not specified. `fastjson.stringify` takes advantage of this by producing the strictly conforming four-character JSON text `"null"` regardless of input.
|
||||||
|
|
||||||
## Performance
|
|
||||||
The `fastjson` functions have demostrated to be between 4,000,000 and 40,000,000 times faster than their built-in `JSON` equivalents on large amounts of data. The benchmarks are open source and [located in this repo](https://github.com/qntm/fastjson/tree/main/benchmarks/).
|
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
* `fastjson` is not a drop-in replacement for the built-in functions `JSON.parse()` and `JSON.stringify()` specified in [ECMA-262§§24.5.1-2](https://www.ecma-international.org/ecma-262/11.0/index.html#sec-json-object).
|
* `fastjson` is not a drop-in replacement for the built-in functions `JSON.parse()` and `JSON.stringify()` specified in [ECMA-262§§24.5.1-2](https://www.ecma-international.org/ecma-262/11.0/index.html#sec-json-object).
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
const fastjson = require('../src/index.js')
|
|
||||||
const chance = new (require('chance'))()
|
|
||||||
const Benchmark = require('benchmark')
|
|
||||||
|
|
||||||
const cyan = '\x1b[1m\x1b[36m'
|
|
||||||
const reset = '\x1b[0m'
|
|
||||||
|
|
||||||
console.log('Running benchmarks...')
|
|
||||||
|
|
||||||
/* Generate big array */
|
|
||||||
const arr = new Array(2 ** 8).fill().map(() => {
|
|
||||||
const obj = {}
|
|
||||||
|
|
||||||
for (let i = 0; i < 2 ** 8; i++) {
|
|
||||||
const key = chance.string({ length: 16 })
|
|
||||||
const value = chance.string({ length: 64 })
|
|
||||||
obj[key] = value
|
|
||||||
}
|
|
||||||
return obj
|
|
||||||
})
|
|
||||||
|
|
||||||
const str = JSON.stringify(arr)
|
|
||||||
|
|
||||||
function runSuite (func, arg, cb) {
|
|
||||||
const suite = new Benchmark.Suite()
|
|
||||||
suite.add(`fastjson.${func}`, () => {
|
|
||||||
fastjson[func](arg)
|
|
||||||
}).add(`JSON.${func}`, () => {
|
|
||||||
JSON[func](arg)
|
|
||||||
}).on('cycle', (event) => {
|
|
||||||
console.log(String(event.target))
|
|
||||||
}).on('complete', function () {
|
|
||||||
console.log(`${cyan}Fastest is: ${this.filter('fastest').map('name')}${reset}`)
|
|
||||||
if (cb) {
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
}).run({ async: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
runSuite('stringify', arr, () => {
|
|
||||||
runSuite('parse', str, null)
|
|
||||||
})
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fastjson",
|
"name": "fastjson",
|
||||||
"version": "2.0.2",
|
"version": "2.0.1",
|
||||||
"description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.",
|
"description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.",
|
||||||
"homepage": "https://github.com/qntm/fastjson",
|
"homepage": "https://github.com/qntm/fastjson",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -19,12 +19,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"postpublish": "npm version patch && git push",
|
"postpublish": "npm version patch && git push",
|
||||||
"pretest": "npx standard",
|
"pretest": "npx standard",
|
||||||
"test": "npx jest",
|
"test": "npx jest"
|
||||||
"bench": "node ./benchmarks/index.js"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"benchmark": "^2.1.4",
|
|
||||||
"chance": "^1.1.7",
|
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"standard": "^16.0.3"
|
"standard": "^16.0.3"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user