1
0
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.

4 changed files with 2 additions and 51 deletions

1
.gitignore vendored
View File

@ -45,4 +45,3 @@ Temporary Items
# mine
coverage
node_modules
package-lock.json

View File

@ -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.
## 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
* `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).

View File

@ -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)
})

View File

@ -1,6 +1,6 @@
{
"name": "fastjson",
"version": "2.0.2",
"version": "2.0.1",
"description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.",
"homepage": "https://github.com/qntm/fastjson",
"repository": {
@ -19,12 +19,9 @@
"scripts": {
"postpublish": "npm version patch && git push",
"pretest": "npx standard",
"test": "npx jest",
"bench": "node ./benchmarks/index.js"
"test": "npx jest"
},
"devDependencies": {
"benchmark": "^2.1.4",
"chance": "^1.1.7",
"jest": "^26.6.3",
"standard": "^16.0.3"
}