lodash trim vs replace
Date tested:
one year ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Test name
Executions per second
lodash trim
1120161.0 Ops/sec
lodash replace
2133328.0 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