Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Chrome 119
Windows
Desktop
one year ago
Test name Executions per second
Function calls 3165074.5 Ops/sec
Conditional operator 3325719.5 Ops/sec
Script Preparation code:
AخA
 
var event = { foo: 'foo', bar: 'bar'}
var result1 = null
var result2 = null
function getName1(event) { return event.foo }
function getName2(event) { return event.foo + event.bar }
var flag1 = true
var flag2 = false
Tests:
  • Function calls

     
    result1 = { name: getName1(event) }
    result2 = { name: getName2(event) }
  • Conditional operator

     
    result1 = { name: flag1 ? event.foo : event.foo + event.bar }
    result2 = { name: flag2 ? event.foo : event.foo + event.bar }