mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2026-09-03 10:21:38 -04:00
This adds moment to perfect date/time sorting with tabulator!
This commit is contained in:
@@ -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
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
var Benchmark = require('benchmark'),
|
||||
moment = require("./../moment.js"),
|
||||
base = moment('2013-05-25');
|
||||
|
||||
module.exports = {
|
||||
name: 'clone',
|
||||
onComplete: function(){},
|
||||
fn: function(){base.clone();},
|
||||
async: true
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
var Benchmark = require('benchmark'),
|
||||
moment = require('./../moment.js'),
|
||||
base = new Date();
|
||||
|
||||
module.exports = {
|
||||
name: 'fromDate',
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
moment(base);
|
||||
},
|
||||
async: true
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
var Benchmark = require('benchmark'),
|
||||
moment = require('./../moment.js'),
|
||||
base = new Date();
|
||||
|
||||
module.exports = {
|
||||
name: 'fromDateUtc',
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
moment.utc(base);
|
||||
},
|
||||
async: true
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
var Benchmark = require('benchmark'),
|
||||
moment = require("./../moment.js");
|
||||
|
||||
var isObjectEmpty_getOwnPropertyNames = function(obj) {
|
||||
if (Object.getOwnPropertyNames) {
|
||||
return (Object.getOwnPropertyNames(obj).length === 0);
|
||||
} else {
|
||||
var k;
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var isObjectEmpty_keys = function(obj) {
|
||||
if (Object.keys) {
|
||||
return (Object.keys(obj).length === 0);
|
||||
} else {
|
||||
var k;
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var isObjectEmpty_forIn = function(obj) {
|
||||
var k;
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
name: 'isObjectEmpty',
|
||||
tests: {
|
||||
"isObjectEmpty -> for..in": {
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
isObjectEmpty_forIn(moment());
|
||||
},
|
||||
async: false
|
||||
},
|
||||
"isObjectEmpty -> Object.keys": {
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
isObjectEmpty_keys(moment());
|
||||
},
|
||||
async: false
|
||||
},
|
||||
"isObjectEmpty -> Object.getOwnPropertyNames": {
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
isObjectEmpty_getOwnPropertyNames(moment());
|
||||
},
|
||||
async: false
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
var Benchmark = require('benchmark'),
|
||||
moment = require('./../moment.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'makeDuration',
|
||||
onComplete: function(){},
|
||||
fn: function(){
|
||||
moment.duration(5, 'years');
|
||||
},
|
||||
async: true
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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,0 +1,43 @@
|
||||
var Benchmark = require('benchmark');
|
||||
|
||||
module.exports = {
|
||||
name: 'zeroFill',
|
||||
tests: {
|
||||
zeroFillMath: {
|
||||
setup: function() {
|
||||
var zeroFillMath = function(number, targetLength, forceSign) {
|
||||
var absNumber = '' + Math.abs(number),
|
||||
zerosToFill = targetLength - absNumber.length,
|
||||
sign = number >= 0;
|
||||
return (sign ? (forceSign ? '+' : '') : '-') +
|
||||
Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
|
||||
}
|
||||
},
|
||||
fn: function() {
|
||||
zeroFillMath(Math.random() * 1e5 | 0, 5);
|
||||
zeroFillMath(Math.random() * 1e5 | 0, 10);
|
||||
zeroFillMath(Math.random() * 1e10 | 0, 20);
|
||||
},
|
||||
async: true
|
||||
},
|
||||
zeroFillWhile: {
|
||||
setup: function() {
|
||||
var zeroFillWhile = function(number, targetLength, forceSign) {
|
||||
var output = '' + Math.abs(number),
|
||||
sign = number >= 0;
|
||||
|
||||
while (output.length < targetLength) {
|
||||
output = '0' + output;
|
||||
}
|
||||
return (sign ? (forceSign ? '+' : '') : '-') + output;
|
||||
}
|
||||
},
|
||||
fn: function() {
|
||||
zeroFillWhile(Math.random() * 1e5 | 0, 5);
|
||||
zeroFillWhile(Math.random() * 1e5 | 0, 10);
|
||||
zeroFillWhile(Math.random() * 1e10 | 0, 20);
|
||||
},
|
||||
async: true
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user