]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added benchmarks for some supported operations
authorjoineral32 <joineral2@gmail.com>
Mon, 15 Aug 2016 21:29:49 +0000 (17:29 -0400)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 3 Sep 2016 06:07:21 +0000 (23:07 -0700)
benchmarks/add.js [new file with mode: 0644]
benchmarks/endOf.js [new file with mode: 0644]
benchmarks/query.js [new file with mode: 0644]
benchmarks/startOf.js [new file with mode: 0644]
benchmarks/subtract.js [new file with mode: 0644]

diff --git a/benchmarks/add.js b/benchmarks/add.js
new file mode 100644 (file)
index 0000000..1892691
--- /dev/null
@@ -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
+};
diff --git a/benchmarks/endOf.js b/benchmarks/endOf.js
new file mode 100644 (file)
index 0000000..e179d94
--- /dev/null
@@ -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
+};
diff --git a/benchmarks/query.js b/benchmarks/query.js
new file mode 100644 (file)
index 0000000..468e57b
--- /dev/null
@@ -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
+        }
+    }
+};
diff --git a/benchmarks/startOf.js b/benchmarks/startOf.js
new file mode 100644 (file)
index 0000000..204e9ad
--- /dev/null
@@ -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
+};
diff --git a/benchmarks/subtract.js b/benchmarks/subtract.js
new file mode 100644 (file)
index 0000000..95211a0
--- /dev/null
@@ -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
+};