Skip to content

Instantly share code, notes, and snippets.

@drew-wallace
Created February 23, 2017 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drew-wallace/2033bf6c9aedd1cfe09e78d8246949da to your computer and use it in GitHub Desktop.
Save drew-wallace/2033bf6c9aedd1cfe09e78d8246949da to your computer and use it in GitHub Desktop.
Deep JSON Equality performance
const _ = require('lodash');
const deepEqual = require('deep-equal');
const value_equals = require('toubkal/lib/util/value_equals');
const request = require("request");
const rp = require('request-promise');
let url = "https://gist.githubusercontent.com/drew-wallace/3dd411fc6b969648cd67a02de58b0329/raw/82b2ec2e8c193f0d1affac047a114e95fa159b74/JMdict-all.json";
rp({
uri: url,
json: true
}).then(function (a) {
let b = [].concat(a);
let c = [].concat(a);
c[c.length - 1] = c[0];
let t0 = 0;
let t1 = 0;
let a1 = 'unanswered';
let a2 = 'unanswered';
for(let i = 0; i < 5; i++) {
console.group('Test ' + (i+1));
t0 = performance.now();
a1 = _.isEqual(a,b)
a2 = _.isEqual(a,c)
t1 = performance.now();
console.log("lodash took " + (t1 - t0) + " milliseconds:", a1, a2);
t0 = performance.now();
a1 = JSON.stringify(a) === JSON.stringify(b);
a2 = JSON.stringify(a) === JSON.stringify(c);
t1 = performance.now();
console.log("stringify took " + (t1 - t0) + " milliseconds:", a1, a2);
t0 = performance.now();
a1 = deepEqual(a,b);
a2 = deepEqual(a,c);
t1 = performance.now();
console.log("deepEqual took " + (t1 - t0) + " milliseconds:", a1, a2);
t0 = performance.now();
a1 = value_equals(a,b);
a2 = value_equals(a,c);
t1 = performance.now();
console.log("value_equal took " + (t1 - t0) + " milliseconds:", a1, a2);
console.groupEnd();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment