Skip to content

Commit

Permalink
Merge pull request #15 from omgaz/test-data
Browse files Browse the repository at this point in the history
Test data
  • Loading branch information
omgaz authored Jul 23, 2019
2 parents 594648d + a3c21fe commit 8a0f9c9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 81 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function diffler(obj1, obj2) {

// If property exists in obj1 and not in obj2 then it has been removed
if (!(key in obj2)) {
if(!diff) { diff = {}; }
diff[key] = {
from: obj1Val,
to: null // using null to specify that the value is empty in obj2
Expand All @@ -26,15 +25,15 @@ function diffler(obj1, obj2) {
// If property is an object then we need to recursively go down the rabbit hole
else if(typeof obj1Val === 'object') {
var tempDiff = diffler(obj1Val, obj2Val);
if(tempDiff) {
if(!diff) { diff = {}; }
diff[key] = tempDiff;
if(Object.keys(tempDiff).length > 0) {
if(tempDiff) {
diff[key] = tempDiff;
}
}
}

// If property is in both obj1 and obj2 and is different
else if (obj1Val !== obj2Val) {
if(!diff) { diff = {}; }
diff[key] = {
from: obj1Val,
to: obj2Val
Expand Down
13 changes: 13 additions & 0 deletions tests/data/json-metadata-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
version: 1,
created: '2019-07-23T09:36:20.719Z',
modified: '2019-07-23T09:36:20.719Z',
assetUrl: 'readme.svg',
type: 'image/svg+xml',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
status: 'draft'
}
26 changes: 26 additions & 0 deletions tests/data/json-metadata-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
version: 2,
created: '2019-07-23T09:36:20.719Z',
modified: '2019-07-23T09:36:20.719Z',
assetUrl: 'stuff/Appicon-readme.svg',
type: 'image/svg+xml',
description: 'Readme icon for git repo',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
status: 'pending',
versionHistory: {
1: {
modified: '2019-07-23T09:36:20.719Z',
assetUrl: 'readme.svg',
type: 'image/svg+xml',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
},
}
}
37 changes: 37 additions & 0 deletions tests/data/json-metadata-v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
version: 3,
created: '2019-07-23T09:36:20.719Z',
modified: '2019-07-23T09:39:25.577Z',
assetUrl: 'stuff/Appicon-readme.png',
type: 'image/png',
description: 'Readme icon for git repo',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
status: 'approved',
versionHistory: {
1: {
modified: '2019-07-23T09:36:20.719Z',
assetUrl: 'readme.svg',
type: 'image/svg+xml',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
},
2: {
modified: '2019-07-23T09:36:20.719Z',
assetUrl: 'stuff/Appicon-readme.svg',
type: 'image/svg+xml',
description: 'Readme icon for git repo',
author: {
id: 14,
name: 'Gary',
},
keywords: ['app logo', 'logo', 'readme'],
}
}
}
78 changes: 4 additions & 74 deletions tests/performance.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,14 @@
const benchmarker = require('./benchmarker');
const diffler = require('../src');
const metadatav3 = require('./data/json-metadata-v3');
const metadatav2 = require('./data/json-metadata-v2');

const suite = function() {
const testObjectA = {
"id": 157538,
"date": "2017-07-21T10:30:34",
"date_gmt": "2017-07-21T17:30:34",
"guid": {
"rendered": "https://www.sitepoint.com/?p=157538"
},
"modified": "2017-07-23T21:56:35",
"modified_gmt": "2017-07-24T04:56:35",
"slug": "why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it",
"status": "publish",
"type": "post",
"link": "https://www.sitepoint.com/why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it/",
"title": {
"rendered": "Why the IoT Threatens Your WordPress Site (and How to Fix It)"
},
"content": {
},
"excerpt": {
},
"author": 72546,
"featured_media": 157542,
"comment_status": "open",
"ping_status": "closed",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [
6132
],
"tags": [
1798,
6298
]
};
const testObjectB = {
"id": 157538,
"date": "2017-07-21T10:30:34",
"date_gmt": "2017-07-21T17:30:34",
"guid": {
"rendered": "https://www.sitepoint.com/?p=157538"
},
"modified": "2017-07-23T21:56:35",
"modified_gmt": "2017-07-24T04:56:35",
"slug": "why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it",
"status": "publish",
"type": "post",
"link": "https://www.sitepoint.com/why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it/",
"title": {
"rendered": "Why the IoT Threatens Your WordPress Site (and How to Fix It)"
},
"content": {
},
"excerpt": {
},
"author": 72546,
"featured_media": 157542,
"comment_status": "open",
"ping_status": "closed",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [
6132
],
"tags": [
1798,
6298
]
};
diffler(testObjectA, testObjectB);
diffler(metadatav2, metadatav3);
}

const ops = benchmarker.bench10(suite);
const benchmark = 236941; // update value to set new benchmark
const benchmark = 222587; // update value to set new benchmark
console.info(`Executed ${ops} ops/s`);
const diff = Math.round(100 - ((benchmark / ops) * 100));

Expand Down

0 comments on commit 8a0f9c9

Please sign in to comment.