Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117
Linux
Desktop
one year ago
Test name Executions per second
indexOf + slice 5545892.5 Ops/sec
split 7282972.5 Ops/sec
Script Preparation code:
AخA
 
var string = "I am the god of hellfire, and I bring you..."
Tests:
  • indexOf + slice

     
    var position = string.indexOf(',');
    if (position === -1) position = string.length;
    var substring = string.slice(0, position);
  • split

     
    var substring = string.split(',')[0];