Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-json-parse

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-parse - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

111

benchmark.js

@@ -11,74 +11,2 @@ 'use strict'

var parseJSON = {}
parseJSON._err = null
parseJSON._value = null
Object.defineProperty(parseJSON, 'data', {
enumerable: false,
get: function () {
throw new Error('no getter for data')
},
set: function (key) {
try {
this._value = JSON.parse(key)
} catch (err) {
this._err = err
}
return key
}
})
Object.defineProperty(parseJSON, 'err', {
enumerable: false,
get: function () {
var result = this._err
this._err = null
return result
}
})
Object.defineProperty(parseJSON, 'value', {
enumerable: false,
get: function () {
var result = this._value
this._value = null
return result
}
})
function literal (data) {
var result = {
err: null,
value: null
}
try {
result.value = JSON.parse(data)
} catch (err) {
result.err = err
}
return result
}
function doSomething (data) {
var count = 0
var keys = Object.keys(data)
for (var i = 0; i < keys.length; i++) {
count++
}
}
suite.add('literal', function literalBench () {
var parsed = literal(myData)
if (parsed.err) {
return
}
// add a loop to simulate some activity here
for (var i = 0; i < max; i++) {
doSomething(parsed.value)
}
})
suite.add('Parse class', function parseBench () {

@@ -92,3 +20,7 @@ var parsed = new Parse(myData)

for (var i = 0; i < max; i++) {
doSomething(parsed.value)
var count = 0
var keys = Object.keys(parsed.value)
for (var k = 0; k < keys.length; k++) {
count++
}
}

@@ -105,3 +37,7 @@ })

for (var i = 0; i < max; i++) {
doSomething(parsed.value)
var count = 0
var keys = Object.keys(parsed.value)
for (var k = 0; k < keys.length; k++) {
count++
}
}

@@ -112,3 +48,3 @@ })

var parsed = safe(myData)
if (parsed.err) {
if (parsed.error) {
return

@@ -119,20 +55,11 @@ }

for (var i = 0; i < max; i++) {
doSomething(parsed.value)
var count = 0
var keys = Object.keys(parsed.value)
for (var k = 0; k < keys.length; k++) {
count++
}
}
})
suite.add('setter', function parseBench () {
parseJSON.data = myData
if (parseJSON.err) {
return
}
var value = parseJSON.value
// add a loop to simulate some activity here
for (var i = 0; i < max; i++) {
doSomething(value)
}
})
suite.add('try catch here', function tryCatchBench () {

@@ -148,3 +75,7 @@ var data = null

for (var i = 0; i < max; i++) {
doSomething(data)
var count = 0
var keys = Object.keys(data)
for (var k = 0; k < keys.length; k++) {
count++
}
}

@@ -151,0 +82,0 @@ })

2

package.json
{
"name": "fast-json-parse",
"version": "1.0.0",
"version": "1.0.1",
"description": "Parse json safely and at max speed",

@@ -5,0 +5,0 @@ "main": "parse.js",

@@ -5,3 +5,4 @@ # fast-json-parse

The fastest way to parse JSON safely.
It is equivalent to [json-parse-safe](http://npm.im/json-parse-safe),
but it set both the `err` and `value` property to null.

@@ -16,4 +17,3 @@ ## Install

Depending on your application, the constructor mode can be faster or
slower.
You can use it as a function or via a contructor, as you prefer.

@@ -20,0 +20,0 @@ ### function

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc