zlib tests for leak and perf

This commit is contained in:
Jean-Francois 2013-11-21 16:38:58 +01:00
parent e30878dd6a
commit fdf9dda8bd
3 changed files with 108 additions and 1 deletions

View File

@ -0,0 +1,57 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var perf = require("../perf/common-perf");
var zlib = require('zlib');
var UNCOMPRESSORS = [
zlib.inflate,
zlib.inflateRaw,
zlib.gunzip,
zlib.unzip
]
var content = '';
for (var i = 0; i < 1024 * 1024; i++) {
content += 'hello worldçoié\uD83D\uDC4D\n';
}
var compressedContent;
zlib.gzip(content, function(err, content) {
compressedContent = content;
perf.startPerf(uncompress, 100)
})
var index = 0;
function uncompress() {
perf.actionStart();
UNCOMPRESSORS[index](compressedContent, function(err, uncompressed) {
if (index < UNCOMPRESSORS.length - 1) {
index++;
uncompress();
} else {
index = 0;
if (perf.canContinue()) {
uncompress();
}
}
});
}

View File

@ -0,0 +1,50 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var perf = require("../perf/common-perf");
var zlib = require('zlib');
var content = '';
var COMPRESSORS = [
zlib.deflate,
zlib.deflateRaw,
zlib.gzip
]
for (var i = 0; i < 1024 * 1024; i++) {
content += 'hello worldçoié\uD83D\uDC4D\n';
}
var index = 0;
function compress() {
perf.actionStart();
COMPRESSORS[index](content, function(err, compressedContent) {
if (index < COMPRESSORS.length - 1) {
index++;
compress();
} else {
index = 0;
if (perf.canContinue()) {
compress();
}
}
});
}
perf.startPerf(compress, 100)

View File

@ -31,7 +31,7 @@ function startPerf(fstart, time) {
go = false;
}, time * 1000);
fstart();
print("Perf test started.");
console.log("Perf test started.");
}
exports.startPerf = startPerf;
function round(n) {