When doing data structure work I’ve started writing micro benchmark files with mitata (https://github.com/evanwashere/mitata) which does a decent job running GC between runs and outputs some very cute graphs and such. I recently rewrote a core container class we use at Notion and for a 5% speed up on a bunch of our public API routes.
OP, I see you have a mitata-inspired benchmark library “benchmate” (https://github.com/3rd/benchmate/tree/master), I’m curious about difference from mitata, what was missing from it, features added? I looked a bit at the code and it’s certainly easier to read… mitata codebase feels like C written by someone who’s too smart.
I was wondering if there is a tool that can profile nodejs code? I did find some options(most of them are web tools) but they dont seem to give out information as much as mitata about what and where my code is used more often although mitata is a benchmarking tool.
What profilers do you use? Thanks :)
Then, connect with Chrome developer tools. You should see a NodeJS icon in the devtools if there’s a node process on your machine listening on the devtools port. You can use SSH port forwarding or similar to connect to processes on other machines like in a production environment.
Use the Chrome developer tools to take a profile, save it to disk, then analyze it using https://profiler.firefox.com
In production we use Datadog to collect and inspect profiles.
Mitata has added a ton of things since then and it's very mature, and it's built by evan so it's definitely the right choice over benchmate. I used benchmate because I can easily extend it to support the upcoming features in BenchJS.
BenchJS is for easily building shareable benchmarks, and I want to evolve it into a nice code analysis tool. It uses Babel and esbuild to transform and bundle the code before it gets evaluated, and I want to use this to extract more useful insights like the number of operations of a given type (ex. array methods), code path analysis (coverage-like), inline indicators of how much % time a line took, etc.