jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
JSON.parse(JSON.stringify(new Date())) isn't the same as new Date(JSON.parse(JSON.stringify(new Date()))).
The strange thing is that new Date(JSON.parse(JSON.stringify(d))) !== new Date(JSON.parse(JSON.stringify(d.toString()))) ... anyone know why that is?
The difference is in the milliseconds part.
The toString() function returns a pretty representation of the date, to be used as display to humans. This representation doesn't have any information about the milliseconds.
You can use getTime() to get the total number of milliseconds since 1970...
Or you can get a complete string representation by calling toJSON or toISOString
See updated examples, Dan M.
<script>
var date = new Date();
var s1 = JSON.stringify(date),
s2 = JSON.stringify(date.toString());
var d1 = new Date(JSON.parse(s1)),
d2 = new Date(JSON.parse(s2));
//output information to console (firebug etc.)
console.log('Original Date.time = ' + date.getTime());
console.log('Raw JSON Date[' + s1 + '].time = ' + d1.getTime());
console.log('String JSON Date[' + s2 + '].time = ' + d2.getTime());
console.log('Raw - String = ' + (d1 - d2) + ' ms');
//alert(date.getTime() + '\n' + s1 + ' = ' + d1.getTime() + '\n' + s2 + ' = ' + d2.getTime());
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Raw date |
| ready |
String date |
| ready |
As number |
| ready |
toJSON |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.