Regexp creation vs memoization

I need to obtain and use regexps from a string. I'm testing wether I should cache regexps or just construct them on demand.
6 years ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Test name Executions per second
constructor 1273732.9 Ops/sec
memoize 2388044.8 Ops/sec
common boilerplate 3612839.0 Ops/sec
Script Preparation code:
Tests:
  • constructor

  • memoize

  • common boilerplate

Open this result on MeasureThat.net