Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test 20230201.3 - includs
(version: 4)
Comparing performance of:
new vs old
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var orderChangeStatusCode = ['1010', '1015', '1020', '1030', '1011', '1016', '1021', '1031', '1012', '1017', '1022', '1032']; var data = [ { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, { orderChangeStatusCode: '1010' }, { orderChangeStatusCode: '1015' }, { orderChangeStatusCode: '1025' }, { orderChangeStatusCode: '1035' }, ];
Tests:
new
var temp = data?.map(goodData => { return orderChangeStatusCode.includes(goodData?.orderChangeStatusCode); }); console.log(temp)
old
var temp = data?.map(goodData => { return ( goodData.orderChangeStatusCode === '1010' || goodData.orderChangeStatusCode === '1015' || goodData.orderChangeStatusCode === '1020' || goodData.orderChangeStatusCode === '1030' || goodData.orderChangeStatusCode === '1011' || goodData.orderChangeStatusCode === '1016' || goodData.orderChangeStatusCode === '1021' || goodData.orderChangeStatusCode === '1031' || goodData.orderChangeStatusCode === '1012' || goodData.orderChangeStatusCode === '1017' || goodData.orderChangeStatusCode === '1022' || goodData.orderChangeStatusCode === '1032' ); }); console.log(temp)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new
old
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 break down the provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark compares two approaches to check if an element exists in a list using JavaScript. The test cases use a predefined array `data` containing 20 objects, each with a unique `orderChangeStatusCode` property. **Approach 1: Using the `includes()` method (New)** In this approach, we use the `includes()` method to check if an element exists in the `orderChangeStatusCode` list. The benchmark definition code is: ```javascript var temp = data?.map(goodData => { return orderChangeStatusCode.includes(goodData?.orderChangeStatusCode); }); console.log(temp); ``` This approach uses a simple and efficient way to check for membership in an array. **Approach 2: Using multiple `===` checks (Old)** In this approach, we use multiple `===` checks to check if the element exists in the `orderChangeStatusCode` list. The benchmark definition code is: ```javascript var temp = data?.map(goodData => { return ( goodData.orderChangeStatusCode === '1010' || goodData.orderChangeStatusCode === '1015' || // ... goodData.orderChangeStatusCode === '1032' ); }); console.log(temp); ``` This approach is more verbose and less efficient than the `includes()` method. **Pros and Cons** * **Inclusion Method (New)**: + Pros: Efficient, concise, and easy to read. + Cons: Requires a specific library (`includes()` method) or built-in function (`Array.prototype.includes()`). * **Multiple `===` Checks (Old)**: + Pros: No external dependencies required. + Cons: Verbose, less efficient, and harder to read. **Library Usage** The benchmark uses the `includes()` method, which is a part of the JavaScript language specification. It does not require any additional libraries. **Special JS Features/Syntax** There are no special JS features or syntax used in this benchmark. Both approaches use standard JavaScript features. **Other Alternatives** If you want to implement an alternative approach to check for membership in an array, you could consider using: * `Array.prototype.includes()`: This method is similar to the `includes()` method but uses a built-in function. * Custom implementation: You can create your own custom function to check for membership in an array. Keep in mind that these alternatives might have different performance characteristics and readability compared to the `includes()` method.
Related benchmarks:
Loop perf
Test Immutable ToJS vs get
Test Immutable ToJS vs single get
Non insensitive sorting
Comments
Confirm delete:
Do you really want to delete benchmark?