Last active
April 15, 2021 02:47
-
-
Save phuong/f86822e2133f6c194c12887e18664c63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const JSONC = require('jsoncomp') | |
const perf = require('execution-time') | |
const sizeof = require('object-sizeof') | |
const _ = require('lodash') | |
const CJSON = require('compress-json') | |
const file = './june.loc.json' | |
let data = fs.readFileSync(file, 'utf-8') | |
data = JSON.parse(data) | |
const orgSize = sizeof(data) | |
console.info('Processing for: ', file) | |
console.info('Original data has: ', orgSize) | |
console.info('----------------------------') | |
console.info('Process with jsoncomp') | |
let timer1 = perf() | |
timer1.start() | |
let compressed = JSONC.compress(data) | |
let timer1Results = timer1.stop() | |
let comSize = sizeof(compressed) | |
console.info('Completed in: ', `${timer1Results.time.toFixed(2)}ms`) | |
console.info('Compressed size:', comSize, `${((orgSize - comSize) / orgSize * 100).toFixed(2)}%`) | |
let decompressed = JSONC.decompress(compressed) | |
console.info('Decompressed size:', sizeof(decompressed)) | |
console.info('Same as original:', _.isEqual(data, decompressed)) | |
console.info('----------------------------') | |
console.info('Process with compressed-json') | |
timer1 = perf() | |
timer1.start() | |
compressed = CJSON.compress(data) | |
timer1Results = timer1.stop() | |
comSize = sizeof(compressed) | |
console.info('Completed in: ', `${timer1Results.time.toFixed(2)}ms`) | |
console.info('Compressed size:', comSize, `${((orgSize - comSize) / orgSize * 100).toFixed(2)}%`) | |
decompressed = CJSON.decompress(compressed) | |
console.info('Decompressed size:', sizeof(decompressed)) | |
console.info('Same as original:', _.isEqual(data,decompressed)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "compress_json_test", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"bytes": "^3.1.0", | |
"compress-json": "^1.0.4", | |
"execution-time": "^1.4.1", | |
"gzip-js": "^0.3.2", | |
"jsoncomp": "^1.6.1", | |
"lodash": "^4.17.21", | |
"object-sizeof": "^1.6.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node --stack-size=65500 compress2.js | |
Processing for: ./june.loc.json | |
Original data has: 2591266 | |
---------------------------- | |
Process with jsoncomp | |
Completed in: 3237.99ms | |
Compressed size: 2217968 14.41% | |
Decompressed size: 2604370 | |
Same as original: false | |
---------------------------- | |
Process with compressed-json | |
Completed in: 77.82ms | |
Compressed size: 1516072 41.49% | |
Decompressed size: 2591266 | |
Same as original: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node --stack-size=65500 compress2.js | |
Processing for: ./virtualstore.json | |
Original data has: 264166 | |
---------------------------- | |
Process with jsoncomp | |
Completed in: 116.57ms | |
Compressed size: 210522 20.31% | |
Decompressed size: 264732 | |
Same as original: false | |
---------------------------- | |
Process with compressed-json | |
Completed in: 24.36ms | |
Compressed size: 150468 43.04% | |
Decompressed size: 264166 | |
Same as original: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment