var string = "Helaas11111111111111111111111111111111111111111111111111111heljhell222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222333333333333343565555ghgfrdfdfdsfshellasdflasdkfjksadfksdflsdfjsdjlfjsdfkjadsfjakdsjfjsadlfklksdjflkjsdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddklllllllllllllllllllllllkkkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdfgafsdfsfdsadfsadfsadsadgfdgaesssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssHello world!";
var regex = /Hello/;
regex.test(string);
string.includes("Hello");
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
regex | |
includes |
Test name | Executions per second |
---|---|
regex | 15926410.0 Ops/sec |
includes | 149258336.0 Ops/sec |
Overview
The provided JSON represents a benchmark test case on MeasureThat.net, which compares the performance of two approaches to search for a specific string within a large input string: regular expression (regex) and string includes.
Benchmark Definition
The benchmark definition is not explicitly stated in the provided code. However, based on the test cases, it appears that the benchmark is comparing the performance of two functions:
string.includes("Hello")
: This function checks if the input string "Hello" is present anywhere within the larger input string.regex.test(string)
: This function uses a regular expression to search for the pattern "Hello" within the larger input string.Options Compared
The benchmark compares two options:
includes()
method to search for the presence of the substring "Hello" in the input string./Hello/
to search for the exact match of the substring "Hello" in the input string.Pros and Cons
String Includes:
Pros:
Cons:
Regular Expression:
Pros:
Cons:
Other Considerations
Library and Purpose
In this benchmark, no explicit library is used. However, the includes()
method is a built-in JavaScript function that searches for the presence of a substring within an input string. The regex pattern /Hello/
is a simple regular expression that matches the exact substring "Hello".
Special JS Feature or Syntax
This benchmark uses the includes()
method and regular expressions (regex), which are standard features in modern JavaScript.
Alternatives
If you were to design a similar benchmark, you could consider additional options, such as: