lodash trim vs replace
Date tested:
5 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
Test name
Executions per second
lodash trim
929239.2 Ops/sec
lodash replace
1970193.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