Added benchmark

master
Vitaly Puzrin 2014-02-03 16:24:19 +04:00
rodzic ee89f49100
commit ac35ad00b2
12 zmienionych plików z 7369 dodań i 0 usunięć

1
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1 @@
/node_modules/

4
.jshintignore 100644
Wyświetl plik

@ -0,0 +1,4 @@
.git/
node_modules/
lib/
/benchmark/implementations

78
.jshintrc 100644
Wyświetl plik

@ -0,0 +1,78 @@
{
// Enforcing Options /////////////////////////////////////////////////////////
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"indent" : 2, // Specify indentation spacing
"latedef" : true, // Prohibit hariable use before definition.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`.
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // Require all non-global variables be declared before they are used.
"unused" : true, // Warns when you define and never use your variables
"strict" : true, // Require `use strict` pragma in every file.
"trailing" : true, // Prohibit trailing whitespaces.
// Relaxing Options //////////////////////////////////////////////////////////
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // Tolerate use of `== null`.
//"es5" : true, // Allow ECMAScript 5 syntax.
"esnext" : false, // Allow ES.next specific features such as const and let
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declaring variables inside of control structures while accessing them later
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
"iterator" : false, // Allow usage of __iterator__ property.
"lastsemic" : false, // Tolerate semicolon omited for the last statement.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : true, // This option suppresses warnings about comma-first coding style
"loopfunc" : false, // Allow functions to be defined within loops.
"multistr" : false, // Tolerate multi-line strings.
"proto" : false, // Allow usage of __proto__ property.
"scripturl" : false, // Tolerate script-targeted URLs.
"smarttabs" : false, // Allow mixed tabs and spaces when the latter are used for alignmnent only.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // true: Tolerate using this in a non-constructor function
// Environments //////////////////////////////////////////////////////////////
"browser" : false, // Defines globals exposed by modern browsers
"couch" : false, // Defines globals exposed by CouchDB
"devel" : false, // Allow developments statements e.g. `console.log();`.
"dojo" : false, // Defines globals exposed by the Dojo Toolkit
"jquery" : false, // Defines globals exposed by the jQuery
"mootools" : false, // Defines globals exposed by the MooTools
"node" : true, // Defines globals exposed when running under Node.JS
"nonstandard" : false, // Defines non-standard but widely adopted globals such as escape and unescape
"prototypejs" : false, // Defines globals exposed by the Prototype
"rhino" : false, // Defines globals exposed when running under Rhino
"wsh" : false, // Defines globals exposed when running under WSH
"yui" : false, // Yahoo User Interface
// Legacy ////////////////////////////////////////////////////////////////////
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.
// Custom globals ///////////////////////////////////////////////////////////
"globals" : { }
}

6
.npmignore 100644
Wyświetl plik

@ -0,0 +1,6 @@
/banchmark/
/test/
/.*
/Makefile

Wyświetl plik

@ -0,0 +1,138 @@
#!/usr/bin/env node
'use strict';
var path = require('path');
var fs = require('fs');
var util = require('util');
var Benchmark = require('benchmark');
var ansi = require('ansi');
var cursor = ansi(process.stdout);
var IMPLS_DIRECTORY = path.join(__dirname, 'implementations');
var IMPLS_PATHS = {};
var IMPLS = [];
fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) {
var file = path.join(IMPLS_DIRECTORY, name),
code = require(file);
IMPLS_PATHS[name] = file;
IMPLS.push({
name: name,
code: code
});
});
var SAMPLES_DIRECTORY = path.join(__dirname, 'samples');
var SAMPLES = [];
fs.readdirSync(SAMPLES_DIRECTORY).sort().forEach(function (sample) {
var filepath = path.join(SAMPLES_DIRECTORY, sample),
extname = path.extname(filepath),
basename = path.basename(filepath, extname),
content = new Uint8Array(fs.readFileSync(filepath)),
title = util.format('%s (%d bytes)', sample, content.length);
function onStart() {
console.log('\nSample: %s', this.name);
}
function onCycle(event) {
cursor.horizontalAbsolute();
cursor.eraseLine();
cursor.write(' > ' + event.target);
}
function onComplete() {
cursor.write('\n');
}
var suite = new Benchmark.Suite(title, {
onStart: onStart,
onComplete: onComplete
});
IMPLS.forEach(function (impl) {
suite.add(impl.name, {
onCycle: onCycle,
onComplete: onComplete,
defer: !!impl.code.async,
fn: function (deferred) {
if (!!impl.code.async) {
impl.code.run(content, function() {
deferred.resolve();
return;
});
} else {
impl.code.run(content, deferred);
return;
}
}
});
});
SAMPLES.push({
name: basename,
title: title,
content: content,
suite: suite
});
});
function select(patterns) {
var result = [];
if (!(patterns instanceof Array)) {
patterns = [ patterns ];
}
function checkName(name) {
return patterns.length === 0 || patterns.some(function (regexp) {
return regexp.test(name);
});
}
SAMPLES.forEach(function (sample) {
if (checkName(sample.name)) {
result.push(sample);
}
});
return result;
}
function run(files) {
var selected = select(files);
if (selected.length > 0) {
console.log('Selected samples: (%d of %d)', selected.length, SAMPLES.length);
selected.forEach(function (sample) {
console.log(' > %s', sample.name);
});
} else {
console.log("There isn't any sample matches any of these patterns: %s", util.inspect(files));
}
selected.forEach(function (sample) {
sample.suite.run();
});
}
module.exports.IMPLS_DIRECTORY = IMPLS_DIRECTORY;
module.exports.IMPLS_PATHS = IMPLS_PATHS;
module.exports.IMPLS = IMPLS;
module.exports.SAMPLES_DIRECTORY = SAMPLES_DIRECTORY;
module.exports.SAMPLES = SAMPLES;
module.exports.select = select;
module.exports.run = run;
run(process.argv.slice(2).map(function (source) {
return new RegExp(source, 'i');
}));

Wyświetl plik

@ -0,0 +1,7 @@
'use strict'
var deflate = require('./deflate');
exports.run = function(data) {
return deflate(data);
}

Wyświetl plik

@ -0,0 +1,7 @@
'use strict'
var deflate = require('./deflate');
exports.run = function(data) {
return deflate(data);
}

Wyświetl plik

@ -0,0 +1,10 @@
'use strict'
var zlib = require('zlib');
exports.async = true;
exports.run = function(data, callback) {
var buffer = new Buffer(data);
zlib.deflate(buffer, callback);
}

Plik diff jest za duży Load Diff

23
package.json 100644
Wyświetl plik

@ -0,0 +1,23 @@
{
"name" : "pako",
"description" : "zlib port to javascript - fast, modularized, with browser support.",
"version" : "0.0.0",
"keywords" : [ "zlib", "deflate", "inflate" ],
"homepage" : "https://github.com/nodeca/pako",
"contributors" : [ "Andrei Tuputcyn (https://github.com/andr83)",
"Vitaly Puzrin (https://github.com/puzrin)" ],
"bugs" : { "url": "https://github.com/nodeca/pako/issues" },
"license" : { "type": "MIT", "url": "https://github.com/nodeca/pako/blob/master/LICENSE" },
"repository" : { "type": "git", "url": "git://github.com/nodeca/pako.git" },
"main" : "./index.js",
"devDependencies" : {
"mocha": "*",
"benchmark": "*",
"ansi": "*",
"zlibjs": "*"
}
}