lodash trim vs replace
Date tested:
4 years ago
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0
Test name
Executions per second
lodash trim
1667736.6 Ops/sec
lodash replace
6995478.5 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js'></script>
Script Preparation code:
var test = ' tom hanks '
Tests:
lodash trim
_.trim(test, ' ,')
lodash replace
_.replace(test, /(^[,\s]+)|([,\s]+$)/g, '')
Open this result on MeasureThat.net