This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are a bunch of updates to tests, benchmarks, packing, and building. This commit works, which is a good place to commit, however, I made pack return a Buffer rather than a SlowBuffer, which made packing even slower. I am now working on optimizing pack and unpack.
- Loading branch information
Showing
7 changed files
with
233 additions
and
77 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
var fs = require('fs'), | ||
sys = require('sys'), | ||
msgpack = require("../lib/msgpack"), | ||
stub = require("./fixtures/stub"); | ||
|
||
var DATA_TEMPLATE = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]}; | ||
var DATA = []; | ||
|
||
for (var i = 0; i < 500000; i++) { | ||
DATA.push(JSON.parse(JSON.stringify(DATA_TEMPLATE))); | ||
} | ||
|
||
function _set_up(callback) { | ||
this.backup = {}; | ||
callback(); | ||
} | ||
|
||
function _tear_down(callback) { | ||
callback(); | ||
} | ||
|
||
exports.benchmark = { | ||
setUp : _set_up, | ||
tearDown : _tear_down, | ||
'JSON.stringify no more than 7x faster than msgpack.pack' : function (test) { | ||
var jsonStr; | ||
var now = Date.now(); | ||
DATA.forEach(function(d) { | ||
jsonStr = JSON.stringify(d); | ||
}); | ||
var stringifyTime = (Date.now() - now); | ||
|
||
var mpBuf; | ||
now = Date.now(); | ||
DATA.forEach(function(d) { | ||
mpBuf = msgpack.pack(d); | ||
}); | ||
var packTime = (Date.now() - now); | ||
|
||
console.log( | ||
"msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" | ||
); | ||
console.log( | ||
"ratio of JSON.stringify/msgpack.pack: " + packTime/stringifyTime | ||
); | ||
test.expect(1); | ||
test.ok( | ||
packTime/stringifyTime < 7, | ||
"msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" | ||
); | ||
test.done(); | ||
}, | ||
'JSON.parse no more than 5x faster than msgpack.unpack' : function (test) { | ||
var jsonStr; | ||
DATA.forEach(function(d) { | ||
jsonStr = JSON.stringify(d); | ||
}); | ||
|
||
var mpBuf; | ||
DATA.forEach(function(d) { | ||
mpBuf = msgpack.pack(d); | ||
}); | ||
|
||
var now = Date.now(); | ||
DATA.forEach(function(d) { | ||
JSON.parse(jsonStr); | ||
}); | ||
var parseTime = (Date.now() - now); | ||
|
||
now = Date.now(); | ||
DATA.forEach(function(d) { | ||
msgpack.unpack(mpBuf); | ||
}); | ||
var unpackTime = (Date.now() - now); | ||
|
||
console.log( | ||
"msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" | ||
); | ||
console.log("ratio of JSON.parse/msgpack.unpack: " + unpackTime/parseTime); | ||
test.expect(1); | ||
test.ok( | ||
unpackTime/parseTime < 5, | ||
"msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" | ||
); | ||
test.done(); | ||
}, | ||
'output above is from three runs of benchmarks' : function (test) { | ||
console.log(); | ||
for (var i = 0; i < 3; i++) { | ||
var mpBuf; | ||
var now = Date.now(); | ||
DATA.forEach(function(d) { | ||
mpBuf = msgpack.pack(d); | ||
}); | ||
console.log('msgpack pack: ' + (Date.now() - now) + ' ms'); | ||
|
||
now = Date.now(); | ||
DATA.forEach(function(d) { | ||
msgpack.unpack(mpBuf); | ||
}); | ||
console.log('msgpack unpack: ' + (Date.now() - now) + ' ms'); | ||
|
||
var jsonStr; | ||
now = Date.now(); | ||
DATA.forEach(function(d) { | ||
jsonStr = JSON.stringify(d); | ||
}); | ||
console.log('json pack: ' + (Date.now() - now) + ' ms'); | ||
|
||
now = Date.now(); | ||
DATA.forEach(function(d) { | ||
JSON.parse(jsonStr); | ||
}); | ||
console.log('json unpack: ' + (Date.now() - now) + ' ms'); | ||
console.log(); | ||
} | ||
|
||
test.expect(1); | ||
test.ok(1); | ||
test.done(); | ||
} | ||
}; |
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