HTML Preparation code:
AخA
 
1
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
2
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash-fp/0.10.4/lodash-fp.min.js"></script>
Script Preparation code:
 
var arr = [{id: 1, name: "Person 1"}, {id: 2, name: "Person 2"}];
Tests:
  • lodash map

     
    var newArr = _.map(arr, function(a) {
      return a.id === 1 ? {id: 1, name: "Person New Name"} : a;
    });
  • es6 map

     
    // ES6
    var newArr = arr.map(function(a) {
      return a.id === 1 ? {id: 1, name: "Person New Name"} : a;
    });
  • lodash findIndex and splice

    x
     
    var index = _.findIndex(arr, {id: 1});
    // Replace item at index using native splice
    arr.splice(index, 1, {id: 100, name: 'Person New Name'});
  • ramda findIndex and splice

     
    const index = R.findIndex(R.propEq('id', 1))(arr)
    arr.splice(index, 1, {id: 100, name: 'Person New Name'});
  • ramda map

     
    var newArr = R.map(function(a) {
      return a.id === 1 ? {id: 1, name: "Person New Name"} : a;
    })(arr);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    lodash map
    es6 map
    lodash findIndex and splice
    ramda findIndex and splice
    ramda map

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 18 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Firefox 137 on Windows
View result in a separate tab
Test name Executions per second
lodash map 800214.8 Ops/sec
es6 map 42949436.0 Ops/sec
lodash findIndex and splice 5924058.5 Ops/sec
ramda findIndex and splice 2106770.0 Ops/sec
ramda map 9059769.0 Ops/sec