Script Preparation code:
x
 
var class1 = { GetImportantValue: () => 1 };
var class2 = { GetImportantValue: () => 2 };
var class3 = { GetImportantValue: () => 3 };
var class4 = { GetImportantValue: () => 4 };
var class5 = { GetImportantValue: () => 5 };
getImportantValueSwitch = (myClassEnum) => {
    switch (myClassEnum.type) {
        case 'MyClass1': return 1;
        case 'MyClass2': return 2;
        case 'MyClass3': return 3;
        case 'MyClass4': return 4;
        case 'MyClass5': return 5;
    }
}
getImportantValuePolymorphism = (myClass) => myClass.GetImportantValue();
Tests:
  • Polymorphism

     
            getImportantValuePolymorphism(class1);
            getImportantValuePolymorphism(class2);
            getImportantValuePolymorphism(class3);
            getImportantValuePolymorphism(class4);
            getImportantValuePolymorphism(class5);
  • Switch

     
            getImportantValueSwitch({type: 'MyClass1'});
            getImportantValueSwitch({type: 'MyClass2'});
            getImportantValueSwitch({type: 'MyClass3'});
            getImportantValueSwitch({type: 'MyClass4'});
            getImportantValueSwitch({type: 'MyClass5'});
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Polymorphism
    Switch

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0
Firefox 136 on Linux
View result in a separate tab
Test name Executions per second
Polymorphism 1360921984.0 Ops/sec
Switch 21414642.0 Ops/sec