Skip to content

Commit

Permalink
🌝 Adjust style to be consistent with jscs
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 9, 2015
1 parent 9d55efe commit 9ae79fd
Show file tree
Hide file tree
Showing 5 changed files with 547 additions and 547 deletions.
58 changes: 29 additions & 29 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@
var attempts = [];

var opts = {
times: DEFAULT_TIMES,
interval: DEFAULT_INTERVAL
times: DEFAULT_TIMES,
interval: DEFAULT_INTERVAL
};

function parseTimes(acc, t){
if(typeof t === 'number'){
acc.times = parseInt(t, 10) || DEFAULT_TIMES;
} else if(typeof t === 'object'){
acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
} else {
throw new Error('Unsupported argument type for \'times\': ' + typeof(t));
}
if(typeof t === 'number'){
acc.times = parseInt(t, 10) || DEFAULT_TIMES;
} else if(typeof t === 'object'){
acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
} else {
throw new Error('Unsupported argument type for \'times\': ' + typeof(t));
}
}

var length = arguments.length;
Expand All @@ -622,19 +622,19 @@
}

function retryInterval(interval){
return function(seriesCallback){
setTimeout(function(){
seriesCallback(null);
}, interval);
};
return function(seriesCallback){
setTimeout(function(){
seriesCallback(null);
}, interval);
};
}

while (opts.times) {

var finalAttempt = !(opts.times-=1);
attempts.push(retryAttempt(opts.task, finalAttempt));
if(!finalAttempt && opts.interval > 0){
attempts.push(retryInterval(opts.interval));
attempts.push(retryInterval(opts.interval));
}
}

Expand Down Expand Up @@ -835,7 +835,7 @@
if(data.length === 0 && q.idle()) {
// call drain immediately if there are no tasks
return async.setImmediate(function() {
q.drain();
q.drain();
});
}
_arrayEach(data, function(task) {
Expand Down Expand Up @@ -951,17 +951,17 @@
}

function _binarySearch(sequence, item, compare) {
var beg = -1,
end = sequence.length - 1;
while (beg < end) {
var mid = beg + ((end - beg + 1) >>> 1);
if (compare(item, sequence[mid]) >= 0) {
beg = mid;
} else {
end = mid - 1;
}
}
return beg;
var beg = -1,
end = sequence.length - 1;
while (beg < end) {
var mid = beg + ((end - beg + 1) >>> 1);
if (compare(item, sequence[mid]) >= 0) {
beg = mid;
} else {
end = mid - 1;
}
}
return beg;
}

function _insert(q, data, priority, callback) {
Expand Down Expand Up @@ -1060,7 +1060,7 @@
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, args);
q[i].apply(null, args);
}
})]));
}
Expand Down
248 changes: 124 additions & 124 deletions perf/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,168 +48,168 @@ console.log("--------------------------------------");


async.eachSeries(versionNames, cloneVersion, function (err) {
if (err) { throw err; }
versions = versionNames.map(requireVersion);

var suites = suiteConfigs
.map(setDefaultOptions)
.reduce(handleMultipleArgs, [])
.map(setName)
.filter(matchesGrep)
.filter(doesNotMatch)
.map(createSuite);

async.eachSeries(suites, runSuite, function () {
var totalTime0 = +totalTime[version0].toPrecision(3);
var totalTime1 = +totalTime[version1].toPrecision(3);

var wins0 = wins[version0];
var wins1 = wins[version1];

if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
// if < 1% difference, we're likely within the margins of error
console.log("Both versions are about equal " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime0 < totalTime1) {
console.log(version0 + " faster overall " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime1 < totalTime0) {
console.log(version1 + " faster overall " +
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
}

if (wins0 > wins1) {
console.log(version0 + " won more benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
} else if (wins1 > wins0) {
console.log(version1 + " won more benchmarks " +
"(" + wins1 + " vs. " + wins0 + ")");
} else {
console.log("Both versions won the same number of benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
}
});
if (err) { throw err; }
versions = versionNames.map(requireVersion);

var suites = suiteConfigs
.map(setDefaultOptions)
.reduce(handleMultipleArgs, [])
.map(setName)
.filter(matchesGrep)
.filter(doesNotMatch)
.map(createSuite);

async.eachSeries(suites, runSuite, function () {
var totalTime0 = +totalTime[version0].toPrecision(3);
var totalTime1 = +totalTime[version1].toPrecision(3);

var wins0 = wins[version0];
var wins1 = wins[version1];

if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
// if < 1% difference, we're likely within the margins of error
console.log("Both versions are about equal " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime0 < totalTime1) {
console.log(version0 + " faster overall " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime1 < totalTime0) {
console.log(version1 + " faster overall " +
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
}

if (wins0 > wins1) {
console.log(version0 + " won more benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
} else if (wins1 > wins0) {
console.log(version1 + " won more benchmarks " +
"(" + wins1 + " vs. " + wins0 + ")");
} else {
console.log("Both versions won the same number of benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
}
});
});

function runSuite(suite, callback) {
suite.on("complete", function () {
callback();
}).run({async: true});
suite.on("complete", function () {
callback();
}).run({async: true});
}

function setDefaultOptions(suiteConfig) {
suiteConfig.args = suiteConfig.args || [[]];
suiteConfig.setup = suiteConfig.setup || function () {};
return suiteConfig;
suiteConfig.args = suiteConfig.args || [[]];
suiteConfig.setup = suiteConfig.setup || function () {};
return suiteConfig;
}

function handleMultipleArgs(list, suiteConfig) {
return list.concat(suiteConfig.args.map(function (args) {
return _.defaults({args: args}, suiteConfig);
}));
return list.concat(suiteConfig.args.map(function (args) {
return _.defaults({args: args}, suiteConfig);
}));
}

function setName(suiteConfig) {
suiteConfig.name = suiteConfig.name + "(" + suiteConfig.args.join(",") + ")";
return suiteConfig;
suiteConfig.name = suiteConfig.name + "(" + suiteConfig.args.join(",") + ")";
return suiteConfig;
}

function matchesGrep(suiteConfig) {
return !!grep.exec(suiteConfig.name);
return !!grep.exec(suiteConfig.name);
}

function doesNotMatch(suiteConfig) {
return !reject.exec(suiteConfig.name);
return !reject.exec(suiteConfig.name);
}

function createSuite(suiteConfig) {
var suite = new Benchmark.Suite();
var args = suiteConfig.args;
var errored = false;

function addBench(version, versionName) {
var name = suiteConfig.name + " " + versionName;

try {
suiteConfig.setup(1);
suiteConfig.fn(version, function () {});
} catch (e) {
console.error(name + " Errored");
errored = true;
return;
var suite = new Benchmark.Suite();
var args = suiteConfig.args;
var errored = false;

function addBench(version, versionName) {
var name = suiteConfig.name + " " + versionName;

try {
suiteConfig.setup(1);
suiteConfig.fn(version, function () {});
} catch (e) {
console.error(name + " Errored");
errored = true;
return;
}

suite.add(name, function (deferred) {
suiteConfig.fn(version, function () {
deferred.resolve();
});
}, _.extend({
versionName: versionName,
setup: _.partial.apply(null, [suiteConfig.setup].concat(args)),
onError: function (err) {
console.log(err.stack);
}
}, benchOptions));
}

suite.add(name, function (deferred) {
suiteConfig.fn(version, function () {
deferred.resolve();
});
}, _.extend({
versionName: versionName,
setup: _.partial.apply(null, [suiteConfig.setup].concat(args)),
onError: function (err) {
console.log(err.stack);
}
}, benchOptions));
}

addBench(versions[0], versionNames[0]);
addBench(versions[1], versionNames[1]);
addBench(versions[0], versionNames[0]);
addBench(versions[1], versionNames[1]);


return suite.on('cycle', function(event) {
var mean = event.target.stats.mean * 1000;
console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
var version = event.target.options.versionName;
if (errored) return;
totalTime[version] += mean;
})
.on('error', function (err) { console.error(err); })
return suite.on('cycle', function(event) {
var mean = event.target.stats.mean * 1000;
console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
var version = event.target.options.versionName;
if (errored) return;
totalTime[version] += mean;
})
.on('error', function (err) { console.error(err); })
.on('complete', function() {
if (!errored) {
var fastest = this.filter('fastest');
if (fastest.length === 2) {
console.log("Tie");
} else {
var winner = fastest[0].options.versionName;
console.log(winner + ' is faster');
wins[winner]++;
if (!errored) {
var fastest = this.filter('fastest');
if (fastest.length === 2) {
console.log("Tie");
} else {
var winner = fastest[0].options.versionName;
console.log(winner + ' is faster');
wins[winner]++;
}
}
}
console.log("--------------------------------------");
console.log("--------------------------------------");
});

}

function requireVersion(tag) {
if (tag === "current") {
return async;
}
if (tag === "current") {
return async;
}

return require("./versions/" + tag + "/");
return require("./versions/" + tag + "/");
}

function cloneVersion(tag, callback) {
if (tag === "current") return callback();

var versionDir = __dirname + "/versions/" + tag;
mkdirp.sync(versionDir);
fs.open(versionDir + "/package.json", "r", function (err, handle) {
if (!err) {
// version has already been cloned
fs.close(handle);
return callback();
}
if (tag === "current") return callback();

var repoPath = path.join(__dirname, "..");
var versionDir = __dirname + "/versions/" + tag;
mkdirp.sync(versionDir);
fs.open(versionDir + "/package.json", "r", function (err, handle) {
if (!err) {
// version has already been cloned
fs.close(handle);
return callback();
}

var cmd = "git clone --branch " + tag + " " + repoPath + " " + versionDir;
var repoPath = path.join(__dirname, "..");

exec(cmd, function (err) {
if (err) {
throw err;
}
callback();
});
var cmd = "git clone --branch " + tag + " " + repoPath + " " + versionDir;

});
exec(cmd, function (err) {
if (err) {
throw err;
}
callback();
});

});
}
Loading

0 comments on commit 9ae79fd

Please sign in to comment.