Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
fast-iso-string
Advanced tools
A way to get the ISO String about 120%~130% faster than using new Date().toISOString()
.
Here's a C++ code rewrite to TypeScript from V8
to get a faster ISO String format date.
See here the original implementation.
First, install the library:
npm i fast-iso-string
Then, you have two exposed methods that you can use:
fastISOString
: That returns the current date as ISO String.fromUnixToISOString
: To parse a unix time that you already have.And then use like this:
import { fastISOString } from 'fast-iso-string';
-const isoString = new Date().toISOString();
+const isoString = fastISOString();
Above, the difference of calling new Date().toISOString()
or using the library.
new Date().toISOString() x 1,419,493 ops/sec ±2.00% (85 sampled runs)
fastISOString() x 3,306,564 ops/sec ±2.75% (85 sampled runs)
Well, I have two reasons:
new Date()
, actually, using just Date.now()
is almost 100% faster than calling new Date()
.new Date
against Date.now
?You might consider this benchmark unfair because I'm using Date.now()
instead of new Date()
. Actually yeah it's not fair, if we use fromUnixToISOString(new Date())
it might be slower as per this and this.
But otherwise, do you know how to get ISO String without calling new Date()
? I don't know, so JavaScript for us to use the Date
object, so I just skip that runtime cost and go directly to what I want, the formatted ISO String, which format you get the start date in doesn't matter.
This also leaves a question: so everything I'm doing with new Date().MY_METHOD
could be faster? Maybe yes. If you parse unix time and extract the information in whatever format you want it could be faster. I just created one of the Date
methods, but you can try and see if you get faster results with other methods.
If you're doing a lot of operations that need to use the ISO String, maybe you should.
It's not because I'm saying that one method is faster than the other, that this will bring some performance improvement to your workflow, the best thing you can do is to do a benchmarking, to learn more, see Preparing and Evaluating Benchmarks by @RafaelGSS.
I need to thank @RafaelGSS for inspiring the creation of this library for his work on performance within NodeJs.
FAQs
A faster implementation of new Date().toISOString().
The npm package fast-iso-string receives a total of 225 weekly downloads. As such, fast-iso-string popularity was classified as not popular.
We found that fast-iso-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.