Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36
Chrome 98
Linux
Desktop
2 years ago
Test name Executions per second
test 7091413.0 Ops/sec
include 12892568.0 Ops/sec
indexof 3956893.5 Ops/sec
Script Preparation code:
x
 
var badWords = ['xxx',
    'vaffanculo',
    'merda',
    'cazzo',
    'figa',
    'culo',
    'dio',
    'porco',
    'porca',
    'coglione',
    'pirla',
    'deficente',
    'bastardo',
    'stronzo',
    'puttana',
    'troia',
    'frocio',
    'cacca',
    'zoccola',
    'bagascia',
    'cane',
    'madre',
    'padre',
    'porco dio',
    'procodio',
    'porca madonna',
    'madonna puttana',
    'cristo',
    'gesu',
    'berlusconi',
    'obama',
    'trump',
    'paperino',
    'pippo',
    'pluto',
    'paperone',
    'tizio',
    'caio',
    'sempronio',
    'cip',
    'ciop',
    'totti',
    'del piero',
    'ronaldo',
    'paperon',
    'paperoni',
    'disney',
    'pinco',
    'pallino',
    'zio',
    'zia',
    'ciao',
    'cane',
    'topo',
    'test',
    'prova',
    'proviamo',
    'nome',
    'cognome',]
var badWordsRegex = new RegExp(`(${badWords.map(s => `\\b${s}\\b`).join('|')})`, 'i')  
Tests:
  • test

     
    badWordsRegex.test("hello")
  • include

     
    badWords.includes("hello")
  • indexof

     
    badWords.indexOf("hello") > -1