<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var _str = 'https://test.org.com/test/test/test/azaza?param1=123123¶m2=890859083459083405jlk&{utms}&test_param=[asd]qwd';
_str.indexOf('{utms}') !== -1
_str.includes('{utms}')
_.includes(_str, '{utms}')
_.indexOf(_str, '{utms}') !== -1
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
string IndexOf | |
string Includes | |
lodash includes | |
lodash indexOf |
Test name | Executions per second |
---|---|
string IndexOf | 9210427.0 Ops/sec |
string Includes | 7060361.0 Ops/sec |
lodash includes | 2927401.8 Ops/sec |
lodash indexOf | 1430293.1 Ops/sec |
The provided JSON represents a JavaScript benchmark test case on MeasureThat.net. The test measures the performance of three different string methods in JavaScript: indexOf
, includes
, and their respective counterparts from the Lodash library, _.indexOf
and _.includes
.
Options being compared:
string.indexOf
: This method searches for a specific substring within a given string.string.includes
: This method checks if a specified value is present in a string._indexOf
: A custom implementation of the indexOf
method using Lodash's utility functions._includes
: A custom implementation of the includes
method using Lodash's utility functions.Pros and Cons:
_indexOf
and _includes
:Other considerations:
lodash.js
library, which provides various utility functions for string manipulation, among other things. In this context, it's used to provide custom implementations of the indexOf
and includes
methods.Benchmark preparation code:
The script preparation code defines a test string _str
, which contains various URL parameters and an object with a property named {utms}
. The HTML preparation code includes the Lodash library, specifically the lodash.min.js
file, to provide access to the _indexOf
and _includes
functions.
Latest benchmark results:
The provided data shows the execution rates for each test case across different browsers and devices. This allows users to compare the performance of native methods with their custom Lodash implementations.
In terms of alternatives, other JavaScript libraries or frameworks (like jQuery) might offer similar string manipulation functionality. However, MeasureThat.net's focus on measuring the performance of specific strings operations makes it an ideal platform for comparing different implementation approaches.