Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String Test indexOf vs Search
(version: 0)
String.indexOf vs String.search using a standard lorum ipsum text.
Comparing performance of:
IndexOf vs Search
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var test_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis ullamcorper semper. Curabitur mauris quam, congue sit amet lacus in, placerat cursus ex. Praesent mauris orci, malesuada ut pellentesque eget, ullamcorper non mi. Etiam a felis at urna aliquet suscipit. Morbi fringilla augue eu felis posuere, et fermentum tellus facilisis. Proin ut sapien ipsum. Proin non pulvinar ante. Duis sed mi quis est varius pulvinar. Phasellus porttitor cursus elementum. Vivamus sagittis lacus sit amet interdum elementum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque vel leo nisi. Nulla vitae ipsum placerat, cursus felis vitae, pellentesque velit. Pellentesque sagittis dignissim est a euismod. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tristique, nunc et sodales imperdiet, massa nulla suscipit nibh, nec pharetra magna lorem nec massa.\n\nNam maximus a massa ac dapibus. Donec at sapien ultricies, vulputate erat non, placerat neque. Aenean non tempor ante. Mauris massa velit, malesuada quis cursus pretium, gravida eu nibh. Nam viverra purus neque, in pretium eros sagittis sed. Aliquam erat volutpat. Praesent ac mattis justo. Integer maximus est lectus. Praesent id consequat metus. Nullam nec venenatis ligula. Cras bibendum malesuada dapibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi libero diam, dignissim eu convallis ac, commodo ut nibh. Nam eu tristique mauris.\n\nMaecenas a diam tortor. Praesent dapibus augue sit amet nibh egestas rutrum. Pellentesque quis ex et ipsum dictum bibendum in eget tortor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec nulla nulla, facilisis laoreet orci vitae, volutpat dapibus massa. Proin eu nunc eu lectus mattis tristique. Maecenas accumsan vel nisi sit amet pharetra. Praesent posuere lorem eu risus fermentum, in dapibus ex rutrum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus molestie blandit neque ut iaculis. Curabitur quam lorem, ullamcorper id nunc ut, molestie malesuada neque. Nulla vitae dui a sapien cursus blandit. Donec vitae posuere nunc, quis pellentesque turpis. Cras eget elit quam. Nunc commodo erat sed purus volutpat, eget pretium sapien consectetur. Donec molestie eu diam quis blandit.\n\nMorbi interdum est ut metus venenatis congue. Cras ornare lacus quis venenatis vulputate. Curabitur bibendum leo in aliquam posuere. Ut commodo auctor leo, non pulvinar turpis cursus ut. Donec aliquam, leo eget lacinia pretium, ipsum purus vehicula elit, non iaculis lacus orci vitae est. Donec rutrum neque felis, id convallis odio accumsan ac. Aenean quis elit accumsan, elementum lacus ac, egestas risus. In hac habitasse platea dictumst. Phasellus blandit scelerisque ullamcorper. Donec tristique porttitor volutpat. In hac habitasse platea dictumst. Mauris feugiat ante risus. Suspendisse placerat, tellus et laoreet tincidunt, urna leo luctus arcu, sit amet egestas mi ante sit amet dui. Donec blandit egestas quam quis fermentum. Quisque consequat pulvinar fringilla.\n\nPellentesque venenatis leo sed cursus pretium. Phasellus quis sapien euismod, auctor dolor sit amet, faucibus ipsum. Mauris sodales, nibh nec aliquet malesuada, orci lectus accumsan velit, nec ultrices massa nisl ac elit. Pellentesque nec dolor odio. Sed pretium accumsan odio, at accumsan est commodo ultricies. Vestibulum vitae ultrices velit, in lacinia eros. Proin et facilisis enim. In molestie quis mi vel molestie. Pellentesque eu purus eros. Aliquam maximus magna sit amet aliquam porta.";
Tests:
IndexOf
var i = test_string.indexOf("molestie");
Search
var i = test_string.search("molestie");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
IndexOf
Search
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Benchmark Definition JSON** The provided JSON represents a JavaScript microbenchmark test case. It consists of two main parts: 1. **Benchmark Definition**: This section defines the benchmark, which includes: * `Name`: The name of the benchmark, "String Test indexOf vs Search". * `Description`: A brief description of the benchmark, explaining that it compares the performance of `indexOf` and `search` methods on a standard Lorem Ipsum text. 2. **Individual test cases**: This section defines two individual test cases: * `IndexOf`: Tests the `indexOf` method of the string using the provided `test_string`. * `Search`: Tests the `search` method of the string using the provided `test_string`. **Options Compared** The benchmark compares the performance of two options: 1. **`indexOf`**: The `indexOf` method returns the index of the first occurrence of a specified value in the string. 2. **`search`**: The `search` method returns the index of the first occurrence of a specified value in the string, ignoring case. **Pros and Cons** Here are some pros and cons of each approach: 1. **`indexOf`**: * Pros: Generally faster than `search`, as it uses a linear search algorithm that is optimized for most use cases. * Cons: May not be suitable for strings where the desired value is not contiguous, as it will return -1 in such cases. 2. **`search`**: * Pros: Can handle strings where the desired value is not contiguous, and it's case-insensitive by default. * Cons: Generally slower than `indexOf`, due to its more complex algorithm. **Library and Purpose** There are no libraries explicitly mentioned in the benchmark definition. However, both `indexOf` and `search` methods are built-in JavaScript functions that operate on strings. **Special JS Features or Syntax** The benchmark uses a standard Lorem Ipsum text, which is not a special feature or syntax. It's simply a string that is used to test the performance of the `indexOf` and `search` methods. **Other Alternatives** If you need to compare the performance of other string comparison methods, such as: * `includes()`: Returns `true` if the specified value is found in the string, without specifying an index. * `lastIndexOf()` or `startsWith()`: Return indices or booleans indicating whether the specified value is found at a specific position in the string. You can add additional test cases to the benchmark definition to include these alternatives.
Related benchmarks:
Find index in string with recursion vs findIndex
String.indexOf vs String.indexOf with the second parameter
String.indexOf(char) vs String.indexOf(char, position)
.includes() vs indexOf() for single-character search in string
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?