Script Preparation code:
x
 
const createItem = (value, index) => ({ id: index, label: "Label" });
const payload = new Array(3).map(createItem);
var action = { payload };
var emptyValues = (source) => {
    const copy = {};
    // create an object with the same properties but empty values
    Object.keys(source).forEach((key) => copy[key] = typeof source[key] === "string" ? "" : null);
    return copy;
};
var extractAttributes = (payload) => payload.attributes;
Tests:
  • using extra data constant

     
    const repository = (payload) => {
        const data = payload.map(extractAttributes);
        return [
            ...data.slice(0, 1).map(emptyValues),
            ...data
        ];
    }
    repository(action.payload);
  • without extra constant

     
    const repository2 = (payload) => {
        return [
            ...payload.slice(0, 1).map(extractAttributes).map(emptyValues),
            ...payload.map(extractAttributes)
        ];
    }
    repository2(action.payload);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    using extra data constant
    without extra constant

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 years ago)
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.101 Safari/537.36
Chrome 53 on Windows
View result in a separate tab
Test name Executions per second
using extra data constant 506654.8 Ops/sec
without extra constant 446609.3 Ops/sec