Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter
(version: 0)
Testing if statement of filter array is in fact
Comparing performance of:
Case 1 vs Case 2
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js'></script>
Script Preparation code:
function filterArray(arrayToFilter, testFunction) { var elementsRemoved = false; var idx; if (!angular.isArray(arrayToFilter) || !angular.isFunction(testFunction)) { return elementsRemoved; } for (idx = arrayToFilter.length - 1; idx >= 0; idx--) { if (!testFunction(arrayToFilter[idx])) { arrayToFilter.splice(idx, 1); elementsRemoved = true; } } return elementsRemoved; }
Tests:
Case 1
filterArray(Array.apply(null, {length: 100}).map(Function.call, Math.random), (x) => x > 0.5)
Case 2
filterArray(Array.apply(null, {length: 10000}).map(Function.call, Math.random), (x) => x > 0.5)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Case 1
Case 2
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):
I'll break down the benchmark and explain what's being tested, compared, and other considerations. **Benchmark Definition** The benchmark definition provides information about the test case, including: * `Name`: "Filter" - This is the name of the benchmark, which in this case is a simple filter function. * `Description`: "Testing if statement of filter array is in fact " - This describes what the benchmark is testing, which is the performance of filtering an array using an if statement. * `Script Preparation Code` and `Html Preparation Code`: These are code snippets that need to be included in the benchmark environment. The script preparation code defines a function called `filterArray`, which takes two arguments: an array to filter and a test function. The html preparation code includes a reference to Angular.js, which is used later. **Individual Test Cases** The individual test cases provide more specific information about what's being tested: * In each test case, the `Benchmark Definition` uses the same `filterArray` function defined in the script preparation code. * The only difference between the two test cases is the size of the array to filter: 100 elements versus 10,000 elements. This suggests that the benchmark is testing the performance of filtering large arrays. **Comparison** The comparison between the two test cases is straightforward: * Case 1 uses a smaller array (100 elements) and takes fewer executions per second. * Case 2 uses a larger array (10,000 elements) and takes more executions per second. This suggests that the benchmark is testing how well the `filterArray` function performs with arrays of varying sizes. **Options Compared** The options being compared are: * Array size: Small vs. Large * Executions per second: Faster vs. Slower **Pros and Cons** * **Small array**: Pro - Easier to compute, faster execution; Con - Less representative of real-world use cases. * **Large array**: Pro - More representative of real-world use cases, but potentially slower execution; Con - Requires more resources, may not be suitable for all environments. Other considerations: * The benchmark uses Angular.js, which is a JavaScript framework that provides additional functionality beyond the standard language. Using a framework like Angular can affect performance and introduce new variables to consider. * The `filterArray` function modifies the original array in place, which may have implications for code readability and maintainability. **Libraries and Special Features** The benchmark uses: * **Angular.js**: A JavaScript framework that provides additional functionality beyond the standard language. In this case, it's used as a dependency in the script preparation code. * **`Function.call`**: A method that calls a function with a specific `this` context. This is used in the `map` method to create a new array. No special JavaScript features or syntax are mentioned in the benchmark definition or test cases. **Alternatives** If this benchmark were written from scratch, alternative approaches might include: * Using a more modern and efficient filtering algorithm, such as `Array.prototype.filter()`. * Using a different data structure, such as a linked list or binary search tree, to improve performance. * Adding additional tests, such as testing with different types of input data or edge cases. However, the current benchmark provides a clear and concise test case that focuses on the performance of filtering an array using an if statement.
Related benchmarks:
FilterArray
JS Filter Test large array
comparing Array.from copy and then splice with filter method
JS Filter Test large array 10000
Comments
Confirm delete:
Do you really want to delete benchmark?