barakplasma / WebSocket-Demo

a Demo of how to use a websocket to push data into a react app
https://objective-ptolemy-a7f7c2.netlify.com/
0 stars 0 forks source link

Improve Date Formatting Performance #1

Closed barakplasma closed 1 year ago

barakplasma commented 6 years ago

I noticed in the Chrome Javascript profiler that the native method is the slowest. When I ran a performance test, I noticed that moment.js is actually the fastest. https://jsperf.com/date-formatting-library-performance/1

perf date

Go figure.

TODO: use Moment.js instead of native for higher performance

barakplasma commented 6 years ago

Turns out that skipping the step where I turn the string into a Date object leads to greater performance in moment js and the others. It also allows me to do a manual formatting via substrings, which is 100x faster. You can see this at https://5b789027b31274296266b067--objective-ptolemy-a7f7c2.netlify.com/ this version of the deployed artifact. const many_dates = Array(10).fill(0).map(() => new Date()).map(d => d.toISOString()); perf date 2

via https://jsperf.com/date-formatting-library-performance Caveat: I noticed that the version I wrote doesn't account for the time zone, and the format is slightly off in regards to the number of digits on the hour place. Easy fixes, but not my cup of tea at this hour.