<div>This is demo</div>
console.log("js preparation");
var re = /o/;
/o/.test('Hello World!');
'Hello World!'.indexOf('o') > -1;
!!'Hello World!'.match(/o/);
re.test('Hello World!');
!!'Hellow World!'.match(re);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
RegExp#test | |
String#indexOf | |
String#match | |
Preallocated RegExp#test | |
Preallocated String#match |
Test name | Executions per second |
---|---|
RegExp#test | 80133112.0 Ops/sec |
String#indexOf | 1029304192.0 Ops/sec |
String#match | 43567412.0 Ops/sec |
Preallocated RegExp#test | 20731668.0 Ops/sec |
Preallocated String#match | 15486220.0 Ops/sec |
Measuring JavaScript performance is an essential task for any developer, and MeasuringThat.net provides a fantastic platform to do just that.
Benchmark Overview
The provided benchmark compares the performance of four approaches:
test()
method on a regular expression object.indexOf()
method on a string.match()
method on a string, which returns an array if found, or null otherwise.test()
method.Options Compared
Each approach is compared in terms of execution speed, with the goal of finding the fastest way to perform the search operation.
Pros and Cons
Library Usage
None of the approaches in this benchmark use external libraries.
Special JS Features/Syntax
There are no special JavaScript features or syntax mentioned in the provided code. However, it's worth noting that some older browsers may have different behavior or performance characteristics for certain methods due to their implementation details.
Other Alternatives
If you're interested in exploring alternative approaches, consider the following:
indexOf
and match
.Keep in mind that the best approach will depend on the specific use case and requirements of your project.