Script Preparation code:
x
 
const myVar = 'test'
const mySet = new Set();
const myMap = new Map();
const myObj = {};
for(let i = 0; i < 100; i++) {
  const newVar = `${myVar}${i}`;
  mySet.add(newVar);
  myMap.set(newVar, 0);
  myObj[newVar] = 0;
}
const length = 100000000;
Tests:
  • Object Assignment

     
    for (let i=0; i < length; i++) {
        myObj.test = 1;
    }
  • Object Assignment + condition

     
    for (let i=0; i < length; i++) {
        if (!myObj.test) myObj.test = 1;
    }
  • Set assignment

     
    for (let i=0; i < length; i++) {
        mySet.add('test');
    }
  • Set assignment + condition

     
    for (let i=0; i < length; i++) {
        if (!mySet.has('test')) mySet.add('test');
    }
  • Map assignment

     
    for (let i=0; i < length; i++) {
        myMap.set('test', 1);
    }
  • Map assignment + condition

     
    for (let i=0; i < length; i++) {
        if (!myMap.get('test')) myMap.set('test', 1);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Object Assignment
    Object Assignment + condition
    Set assignment
    Set assignment + condition
    Map assignment
    Map assignment + condition

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Firefox 119 on Linux
View result in a separate tab
Test name Executions per second
Object Assignment 10185250.0 Ops/sec
Object Assignment + condition 10208501.0 Ops/sec
Set assignment 10278274.0 Ops/sec
Set assignment + condition 10246101.0 Ops/sec
Map assignment 10304539.0 Ops/sec
Map assignment + condition 10249774.0 Ops/sec