Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions perf/albums.json

Large diffs are not rendered by default.

Binary file added perf/albums.msgpack
Binary file not shown.
19 changes: 19 additions & 0 deletions perf/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Msgpack vs JSON</title>
</head>
<body>
<h1>Msgpack vs JSON</h1>
<table id="results">
<tr>
<th>Operation</th>
<th>Total time</th>
<th>Time per operation</th>
</tr>
</table>
<script type="text/javascript" src="../msgpack.js"></script>
<script type="text/javascript" src="perf.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions perf/perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(function() {
"use strict";
var iterations = 100;
function fetch(path, responseType, callback) {
var req = new XMLHttpRequest();
req.responseType = responseType || 'text';
req.onreadystatechange = function() {
if (req.readyState === 4) {
callback(req.response);
}
};
req.open('GET', path);
req.send();
}
function test(title, obj, operation, context) {
var result;
var start = new Date();
console.group(title);
console.time(title);
for (var i = 0; i < iterations; i++) {
result = operation.call(context, obj);
}
console.timeEnd(title);
var total = new Date() - start;
var op = total/iterations;
console.log('Total for %s was %sms, %sms per operation', title, total, op);
console.groupEnd(title);

var tableEl = document.getElementById('results');
var rowEl = document.createElement('tr');

var titleEl = document.createElement('td');
titleEl.textContent = title;
rowEl.appendChild(titleEl);

var totalEl = document.createElement('td');
totalEl.textContent = total + 'ms';
rowEl.appendChild(totalEl);

var opEl = document.createElement('td');
opEl.textContent = op + 'ms';
rowEl.appendChild(opEl);

tableEl.appendChild(rowEl);
return result;
}
function testDecode(title, path, responseType, operation, context, callback) {
fetch(path, responseType, function(response) {
var result = test(title, response, operation, context)
callback(result);
});
}

testDecode('json decode', 'albums.json', 'text', JSON.parse, JSON, function(obj) {
test('json encode', obj, JSON.stringify, JSON);
});

testDecode('msgpack decode', 'albums.msgpack', 'arraybuffer', msgpack.decode, msgpack, function(obj) {
test('msgpack encode', obj, msgpack.encode, msgpack);
});

}).call(this);