Date creation

Benchmark created by Sammy Knudsen on


Setup

var rgx = {
  	datesplit: /-| |:|\./g
  };
  
  var stringDates = [
  	"2017-01-01 00:00:00.000",
  	"2017-01-02 00:00:00.000",
  	"2017-01-03 00:00:00.000",
  	"2017-01-04 00:00:00.000",
  	"2017-01-05 00:00:00.000",
  	"2017-01-06 00:00:00.000",
  	"2017-01-07 00:00:00.000",
  	"2017-01-08 00:00:00.000",
  	"2017-01-09 00:00:00.000",
  	"2017-01-10 00:00:00.000",
  	"2017-01-11 00:00:00.000",
  	"2017-01-12 00:00:00.000",
  	"2017-01-13 00:00:00.000",
  	"2017-01-14 00:00:00.000",
  	"2017-01-15 00:00:00.000",
  	"2017-01-16 00:00:00.000",
  	"2017-01-17 00:00:00.000",
  	"2017-01-18 00:00:00.000",
  	"2017-01-19 00:00:00.000",
  	"2017-01-20 00:00:00.000",
  	"2017-01-21 00:00:00.000",
  	"2017-01-22 00:00:00.000",
  	"2017-01-23 00:00:00.000",
  	"2017-01-24 00:00:00.000",
  	"2017-01-25 00:00:00.000",
  	"2017-01-26 00:00:00.000",
  	"2017-01-27 00:00:00.000",
  	"2017-01-28 00:00:00.000",
  	"2017-01-29 00:00:00.000",
  	"2017-01-30 00:00:00.000",
  	"2017-01-31 00:00:00.000"
  ];
  
  var arrayDates = [
  	[2017, 0, 1, 0, 0, 0, 0],
  	[2017, 0, 2, 0, 0, 0, 0],
  	[2017, 0, 3, 0, 0, 0, 0],
  	[2017, 0, 4, 0, 0, 0, 0],
  	[2017, 0, 5, 0, 0, 0, 0],
  	[2017, 0, 6, 0, 0, 0, 0],
  	[2017, 0, 7, 0, 0, 0, 0],
  	[2017, 0, 8, 0, 0, 0, 0],
  	[2017, 0, 9, 0, 0, 0, 0],
  	[2017, 0, 10, 0, 0, 0, 0],
  	[2017, 0, 11, 0, 0, 0, 0],
  	[2017, 0, 12, 0, 0, 0, 0],
  	[2017, 0, 13, 0, 0, 0, 0],
  	[2017, 0, 14, 0, 0, 0, 0],
  	[2017, 0, 15, 0, 0, 0, 0],
  	[2017, 0, 16, 0, 0, 0, 0],
  	[2017, 0, 17, 0, 0, 0, 0],
  	[2017, 0, 18, 0, 0, 0, 0],
  	[2017, 0, 19, 0, 0, 0, 0],
  	[2017, 0, 20, 0, 0, 0, 0],
  	[2017, 0, 21, 0, 0, 0, 0],
  	[2017, 0, 22, 0, 0, 0, 0],
  	[2017, 0, 23, 0, 0, 0, 0],
  	[2017, 0, 24, 0, 0, 0, 0],
  	[2017, 0, 25, 0, 0, 0, 0],
  	[2017, 0, 26, 0, 0, 0, 0],
  	[2017, 0, 27, 0, 0, 0, 0],
  	[2017, 0, 28, 0, 0, 0, 0],
  	[2017, 0, 29, 0, 0, 0, 0],
  	[2017, 0, 30, 0, 0, 0, 0],
  	[2017, 0, 31, 0, 0, 0, 0]
  ];

Test runner

Ready to run.

Testing in
TestOps/sec
Date arguments from array
var x, i = 30;

for (; i !== -1; --i) {
	x = new Date(arrayDates[i][0], arrayDates[i][1], arrayDates[i][2], arrayDates[i][3], arrayDates[i][4], arrayDates[i][5], arrayDates[i][6]);
}
ready
Date arguments from array reference
var x, a, i = 30;
for (; i !== -1; --i) {
	a = arrayDates[i];
	x = new Date(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);
}
ready
Date arguments from array after regex split
var x, a, i = 30;
for (; i !== -1; --i) {
	a = stringDates[i].split(rgx.datesplit);
	x = new Date(a[0], a[1]-1, a[2], a[3], a[4], a[5], a[6]);
}
ready
Date argument as string
var x, i = 30;
for (; i !== -1; --i) {
	x = new Date(stringDates[i]);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Sammy Knudsen on