Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
getRelevantPositions2
(version: 1)
Comparing performance of:
Stara opcja vs Nowa opcja
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var IRRELEVANT_PARAGRAPHS = [ '401', '402', '404', '405', '406', '407', '408', '409', '410', '411', '412', '417', '418', '471', '474', '475', '478', '479', '480', '483', '484', '485', '801', '804', '806', '807', '808', '809', '810', '811', '812', '813', '814', '605', '606', '610', '613', '615', '617', '619', '620', '621', '622', '623', '625', '630', '637', '647', '648', '649', '656', '657', '658', '659', '661', '662', '663', '664', '665', '666', '669', '672', '680', ]; var IRRELEVANT_GROUPS = ['1400', '1810', '1600', '1601', '1602', '1610', '1611', '1612']; var positions = []; var classificationDetailLevels = ['paragraph', 'systemGroup', 'ordinanceGroup']; for (let i = 0; i < 10000; i++) { const randomIndex = Math.floor(Math.random() * classificationDetailLevels.length); positions.push({ paragraph: `Paragraph ${Math.floor(Math.random() * 10)}`, group: `Group ${Math.floor(Math.random() * 5)}`, }); }
Tests:
Stara opcja
const getRelevantPositions = (outgoings, classificationDetailLevel) => outgoings.filter((position) => { switch (classificationDetailLevel) { case 'paragraph': return position.paragraph && !IRRELEVANT_PARAGRAPHS.includes(position.paragraph); case 'systemGroup': case 'ordinanceGroup': return position.group && !IRRELEVANT_GROUPS.includes(position.group); default: return false; } }); classificationDetailLevels.forEach((classificationDetailLevel) => getRelevantPositions(positions, classificationDetailLevel))
Nowa opcja
const getRelevantPositions = (outgoings, classificationDetailLevel) => { let condition; switch (classificationDetailLevel) { case 'paragraph': condition = (position) => position.paragraph && !IRRELEVANT_PARAGRAPHS.includes(position.paragraph); break; case 'systemGroup': case 'ordinanceGroup': condition = (position) => position.group && !IRRELEVANT_GROUPS.includes(position.group); break; } return outgoings.filter(condition) } classificationDetailLevels.forEach((classificationDetailLevel) => getRelevantPositions(positions, classificationDetailLevel))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Stara opcja
Nowa opcja
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Stara opcja
405.6 Ops/sec
Nowa opcja
413.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of JavaScript code is crucial to understand its efficiency and scalability. Let's break down what's being tested in this benchmark. **Benchmark Definition** The benchmark defines two test cases, "Stara opcja" (Old approach) and "Nowa opcja" (New approach), which aim to measure the performance of a function `getRelevantPositions` that filters an array of objects based on certain conditions. The input data is generated by creating 10,000 random positions with paragraph and group properties. **Options Compared** The two test cases compare the performance of the following approaches: 1. **Stara opcja (Old approach)**: This implementation uses a `switch` statement to define the filtering condition for each classification detail level. It then applies this filter to the entire array of positions using the `filter()` method. 2. **Nowa opcja (New approach)**: This implementation uses a more modular approach, defining separate functions for each filtering condition. The main function, `getRelevantPositions`, takes an array of positions and a classification detail level as input. It then creates a filter function based on the classification detail level and applies it to the entire array. **Pros and Cons** **Stara opcja (Old approach)**: Pros: * Simplistic and easy to understand * Less overhead due to the absence of function creation Cons: * The `switch` statement can lead to slower performance compared to other approaches * The filter condition is applied globally, which might not be optimal for large datasets **Nowa opcja (New approach)**: Pros: * More modular and reusable code * Can take advantage of the filtering mechanism to optimize performance Cons: * Creates additional function objects, which can lead to overhead * Requires more code to set up the filtering conditions **Library Usage** In this benchmark, no external libraries are used. The filtering logic is implemented directly in the test cases. **Special JavaScript Features or Syntax** There are no special features or syntax used in this benchmark that would require additional explanation. **Other Alternatives** Other alternatives for optimizing the `getRelevantPositions` function might include: 1. **Use a `map()` function to create an array of filtered positions**: This approach can be more efficient than using a global filter condition, as it avoids the overhead of filtering the entire array. 2. **Use a `forEach()` loop with an iterator**: This approach can provide better performance than the `filter()` method, especially for large datasets. 3. **Use a library like Lodash or Ramda for functional programming**: These libraries provide optimized implementations of common functions, including filtering and mapping. Keep in mind that the best approach will depend on the specific requirements and constraints of your project.
Related benchmarks:
ArrayFind
array test 123123123123
spread vs concat vs unshift Big string array
getRelevantPositions
Comments
Confirm delete:
Do you really want to delete benchmark?