regexp versus includes

Benchmark created on


Setup

const TESTS = [
    {
        agent: 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
        result: true,
    },
    {
        agent: 'Mozilla/5.0 (compatible; YandexBot/3.0; MirrorDetector; +http://yandex.com/bots)',
        result: true,
    },
    {
        agent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
        result: true,
    },
];

Test runner

Ready to run.

Testing in
TestOps/sec
regexp
TESTS.forEach((item) => {
/googlebot|yandexbot|bingbot/.test(item.agent.toLowerCase())
})
ready
indexof
TESTS.forEach((item) => {
	const agentStr = item.agent.toLowerCase();

    [
        'googlebot',
        'yandexbot',
        'bingbot',
    ].some((v) => agentStr.indexOf(v) >= 0);
})
ready

Revisions

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