Skip to content

Commit

Permalink
Added benchmarks for some supported operations
Browse files Browse the repository at this point in the history
  • Loading branch information
joineral32 authored and ichernev committed Sep 3, 2016
1 parent cbc3621 commit 6f9f5b0
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
22 changes: 22 additions & 0 deletions benchmarks/add.js
@@ -0,0 +1,22 @@
var Benchmark = require('benchmark'),
moment = require("./../moment.js"),
base = moment('2013-05-25');

var unitsUnderTest = ["milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "quarters", "years"];
var tests = unitsUnderTest.reduce(function (testsSoFar, unit) {
testsSoFar["add " + unit] = generateTestForUnit(unit);
return testsSoFar;
}, {});

function generateTestForUnit(unit) {
return {
setup: function(){var base = base; var unit = unit;},
fn: function(){base.add(8, unit);},
async: true
};
}

module.exports = {
name: 'add',
tests: tests
};
22 changes: 22 additions & 0 deletions benchmarks/endOf.js
@@ -0,0 +1,22 @@
var Benchmark = require('benchmark'),
moment = require("./../moment.js"),
base = moment('2013-05-25');

var unitsUnderTest = ["second", "minute", "hour", "date", "day", "isoWeek", "week", "month", "quarter", "year"];
var tests = unitsUnderTest.reduce(function (testsSoFar, unit) {
testsSoFar["endOf " + unit] = generateTestForUnit(unit);
return testsSoFar;
}, {});

function generateTestForUnit(unit) {
return {
setup: function(){var base = base; var unit = unit;},
fn: function(){base.endOf(unit);},
async: true
};
}

module.exports = {
name: 'endOf',
tests: tests
};
40 changes: 40 additions & 0 deletions benchmarks/query.js
@@ -0,0 +1,40 @@
var Benchmark = require('benchmark'),
moment = require("./../moment.js"),
base = moment('2013-05-25');


module.exports = {
name: 'clone',
tests: {
isBefore_true: {
onComplete: function(){},
fn: function(){base.isBefore('2013-06-25');},
async: true
},
isBefore_self: {
onComplete: function(){},
fn: function(){base.isBefore('2013-05-25');},
async: true
},
isBefore_false: {
onComplete: function(){},
fn: function(){base.isBefore('2013-04-25');},
async: true
},
isAfter_true: {
onComplete: function(){},
fn: function(){base.isAfter('2013-04-25');},
async: true
},
isAfter_self: {
onComplete: function(){},
fn: function(){base.isAfter('2013-05-25');},
async: true
},
isAfter_false: {
onComplete: function(){},
fn: function(){base.isAfter('2013-06-25');},
async: true
}
}
};
22 changes: 22 additions & 0 deletions benchmarks/startOf.js
@@ -0,0 +1,22 @@
var Benchmark = require('benchmark'),
moment = require("./../moment.js"),
base = moment('2013-05-25');

var unitsUnderTest = ["second", "minute", "hour", "date", "day", "isoWeek", "week", "month", "quarter", "year"];
var tests = unitsUnderTest.reduce(function (testsSoFar, unit) {
testsSoFar["startOf " + unit] = generateTestForUnit(unit);
return testsSoFar;
}, {});

function generateTestForUnit(unit) {
return {
setup: function(){var base = base; var unit = unit;},
fn: function(){base.startOf(unit);},
async: true
};
}

module.exports = {
name: 'startOf',
tests: tests
};
22 changes: 22 additions & 0 deletions benchmarks/subtract.js
@@ -0,0 +1,22 @@
var Benchmark = require('benchmark'),
moment = require("./../moment.js"),
base = moment('2013-05-25');

var unitsUnderTest = ["milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "quarters", "years"];
var tests = unitsUnderTest.reduce(function (testsSoFar, unit) {
testsSoFar["subtract " + unit] = generateTestForUnit(unit);
return testsSoFar;
}, {});

function generateTestForUnit(unit) {
return {
setup: function(){var base = base; var unit = unit;},
fn: function(){base.subtract(8, unit);},
async: true
};
}

module.exports = {
name: 'subtract',
tests: tests
};

0 comments on commit 6f9f5b0

Please sign in to comment.