Permalink
Browse files

Added benchmarks for some supported operations

  • Loading branch information...
1 parent cbc3621 commit 6f9f5b026932b7cb3a0d1a8a613b49cac16afd42 @joineral32 joineral32 committed with ichernev Aug 15, 2016
Showing with 128 additions and 0 deletions.
  1. +22 −0 benchmarks/add.js
  2. +22 −0 benchmarks/endOf.js
  3. +40 −0 benchmarks/query.js
  4. +22 −0 benchmarks/startOf.js
  5. +22 −0 benchmarks/subtract.js
View
@@ -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
+};
View
@@ -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
+};
View
@@ -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
+ }
+ }
+};
View
@@ -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
+};
@@ -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.