string indexOf vs string includes perfromance

Benchmark created on


Setup

const testString1 = "apple,orange,banana,grape,kiwi,mango,pineapple," +
                    "watermelon,lemon,blueberry,peach,pear,strawberry," +
                    "raspberry,blackberry,avocado,papaya,pomegranate," +
                    "apricot,nectarine,fig,guava,dragonfruit,persimmon," +
                    "kumquat,passionfruit,lychee,coconut,cranberry," +
                    "elderberry,boysenberry,loganberry,mulberry," +
                    "gooseberry,blackcurrant,redcurrant,whitecurrant," +
                    "cherimoya,plantain,starfruit,quince," +
                    "tiger,lion,elephant,giraffe,zebra,cheetah," +
                    "penguin,koala,kangaroo,koala,platypus," +
                    "ostrich,lemur,meerkat,sloth,armadillo," +
                    "whale,dolphin,shark,seahorse,starfish," +
                    "cactus,rose,lily,tulip,sunflower," +
                    "ocean,mountain,desert,forest,sky," +
                    "moon,sun,star,planet,globe," +
                    "chocolate,coffee,tea,ice cream,cake," +
                    "keyboard,mouse,monitor,laptop,tablet," +
                    "book,pen,pencil,paper,eraser," +
                    "guitar,piano,violin,drums,trumpet," +
                    "car,bicycle,motorcycle,train,plane," +
                    "ship,rocket,submarine,balloon,unicorn";
                    
                    
const searchString1 = "unicorn";

Test runner

Ready to run.

Testing in
TestOps/sec
include
console.log("Test Case 1: String.includes", () => {
  testString1.includes(searchString1);
ready
indexOf
console.log("Test Case 1: String.includes", () => {
  testString1.indexOf(searchString1);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.