Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Temp123
(version: 0)
Comparing performance of:
.includes vs .includes new array vs .some
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.FOO = [ 'Detached House', 'Detached Property', 'Semi-Detached House', 'Semi-Detached Property', 'End Terrace House', 'End Terrace Property', 'Mid Terrace House', 'Mid Terrace Property', 'Terrace Property', 'Terraced', 'Converted Flat', 'Flat/Maisonette', 'Purpose Built Flat', 'Bungalow Property', 'Detached Bungalow', 'End Terrace Bungalow', 'Mid Terrace Bungalow', 'Semi-Detached Bungalow', 'Terraced Bungalow', 'barn_conversion', 'cottage', 'country_house', 'detached', 'farmhouse', 'link_detached', 'lodge', 'semi_detached', 'end_terrace', 'mews', 'terraced', 'town_house', 'flat', 'maisonette', 'studio', 'detached_bungalow', 'semi_detached_bungalow', 'terraced_bungalow', 'bungalow' ];
Tests:
.includes
const isTemp = (foo) => { typeof foo === 'string' && FOO.includes(foo); }; isTemp('maisonette');
.includes new array
const isTemp = (foo) => { const BAR = [...FOO]; typeof foo === 'string' && BAR.includes(foo); }; isTemp('maisonette');
.some
const isTemp = (foo) => { typeof foo === 'string' && FOO.some((bar) => bar === foo); }; isTemp('maisonette');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
.includes
.includes new array
.some
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark that tests three different approaches for determining whether a string is present in an array. The benchmark is designed to measure the performance difference between using the `includes()` method, creating a new array and searching for the value, and using the `some()` method. **Test Cases** There are three individual test cases: 1. **`.includes`**: This test case uses the built-in `includes()` method to search for the string `'maisonette'` in the `FOO` array. 2. **`.includes new array`**: This test case creates a new array `BAR` by spreading the `FOO` array, and then uses the `includes()` method on `BAR` to search for the string `'maisonette'`. 3. **`.some`**: This test case uses the `some()` method to check if any element in the `FOO` array is equal to the string `'maisonette'`. **Options Compared** The benchmark compares three different approaches: * **`.includes()`**: This approach uses the built-in `includes()` method, which creates a new array with the elements that match the search value. * **`.includes new array`**: This approach creates a new array by spreading the original array and then uses the `includes()` method on the new array. This approach avoids creating a new array with the matching elements, but still creates an intermediate array. * **`.some()`**: This approach uses the `some()` method, which checks if any element in the array meets the condition. **Pros and Cons of Each Approach** 1. **`.includes()`**: * Pros: Short and concise code, easy to understand and maintain. * Cons: Creates a new array with the matching elements, which can be memory-intensive for large arrays. 2. **`.includes new array`**: * Pros: Avoids creating a new array with the matching elements, reduces memory usage. * Cons: Requires creating an intermediate array by spreading the original array. 3. **`.some()`**: * Pros: Can be more efficient than `includes()` if the array is very large and only contains one element that matches the search value. * Cons: May require additional logic to handle cases where no elements match. **Library Usage** The benchmark uses the following library: * `FOO`: An array of strings defined in the `Script Preparation Code`. **Special JS Feature or Syntax** There are no special JS features or syntax used in this benchmark. The code is simple and straightforward, using only built-in methods and standard JavaScript syntax. **Other Alternatives** If you're looking for alternative approaches to these methods, you can consider: * Using the `indexOf()` method instead of `includes()`, which returns the index of the first occurrence or -1 if not found. * Using a custom loop or recursion to iterate through the array and check each element manually. * Using a library like Lodash that provides optimized implementations of these methods. However, for most cases, the built-in `includes()` method is sufficient and efficient enough.
Related benchmarks:
Unique via Set vs Filter
safdfsda
[Sort selected first] Sort vs remove and concat
Word width calculation speed
Comments
Confirm delete:
Do you really want to delete benchmark?