one line vs old

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Setup

var a = 'ap-northeast-1'

Test runner

Ready to run.

Testing in
TestOps/sec
old
let formatedName = a
    .replace(/\w+/g, word => word.charAt(0).toUpperCase() + word.substring(1))
    .replaceAll('-', '')
  formatedName = formatedName.charAt(0).toLowerCase() + formatedName.slice(1)
  return formatedName
ready
one line
a
    .toLowerCase()
    .replace(/-([a-z0-9])/g, (_, ltr) =>
      ltr.toUpperCase(),
    )
ready
lodash
_.camelCase(a)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.