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 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15
Test name Executions per second
constructor 1327904.9 Ops/sec
memoize 1564369.1 Ops/sec
common boilerplate 1170341.9 Ops/sec
Script Preparation code:
Tests:
  • constructor

  • memoize

  • common boilerplate

Open this result on MeasureThat.net