var string = "Hello world!";
var regex = /hello/i;
var search = "hello";
regex.test(string);
string.toUpperCase().includes(search.toUpperCase());
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
regex | |
includes |
Test name | Executions per second |
---|---|
regex | 56393596.0 Ops/sec |
includes | 2834428672.0 Ops/sec |
Benchmark Overview
The provided JSON represents a JavaScript benchmark on MeasureThat.net, which compares the performance of regular expressions (regex) and the includes
method in case-insensitive searches.
Tested Options
There are two test cases:
/hello/i;
) to search for the string "hello" (case-insensitive).toUpperCase()
method followed by the includes()
method to search for the uppercase version of the string "hello".Pros and Cons
toUpperCase()
method, which can introduce additional processing steps.Library Usage
In this benchmark, no libraries are explicitly mentioned. However, the includes
method is a built-in JavaScript method that is widely supported across browsers and platforms.
Special JS Features or Syntax
This benchmark uses:
/hello/i;
regex pattern and the .toUpperCase()
method with includes()
use case-insensitive searching.Other Alternatives
If you wanted to test alternative approaches, you could consider adding additional test cases for:
startsWith()
and endsWith()
methods instead of regex.These alternative approaches could provide additional insights into performance differences between various techniques.