Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
not not vs yes
(version: 0)
!! vs !!!
Comparing performance of:
Yes vs not not
Created:
6 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
arr = new Array(100).fill(6); arrWithNots = new Array(20).fill(null); test = [arr, arrWithNots];
Tests:
Yes
test.filter(x => x);
not not
test.filter(x => !!x);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Yes
not not
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 explain the benchmark in detail. **Benchmark Overview** The provided benchmark compares two approaches to filter an array of numbers using JavaScript's `filter()` method: one that uses a simple logical NOT operator (`!!`) and another that uses a double bangbang notation (`!!!`). **Options Compared** Two options are compared: 1. **Simple Logical NOT Operator (`!!`)**: This approach uses the unary negative sign and two exclamation marks to invert the truthiness of each element in the array. 2. **Double Bangbang Notation (`!!!`)**: This approach uses two consecutive exclamation marks to achieve similar effect as the logical NOT operator. **Pros and Cons** 1. **Simple Logical NOT Operator (`!!`)**: * Pros: Easy to understand, widely supported by most browsers. * Cons: May not be the most efficient way to filter an array, as it creates a new array with the inverted values. 2. **Double Bangbang Notation (`!!!`)**: * Pros: Can potentially be more efficient than using `!!`, as it avoids creating a new array. * Cons: Less intuitive and less widely supported by older browsers. **Library** There is no library used in this benchmark. The test cases only use built-in JavaScript functions (`filter()`). **Special JS Feature or Syntax** No special features or syntax are used in this benchmark. It only relies on standard JavaScript language constructs. **Benchmark Preparation Code** The preparation code creates two arrays: `arr` with 100 elements set to the value 6, and `arrWithNots` with 20 elements set to null. The test variable `test` is an array containing both `arr` and `arrWithNots`. **Individual Test Cases** There are two individual test cases: 1. **"Yes"`**: Filters the entire `arr` array using the `filter()` method without any modifications. 2. **"not not"`**: Filters the entire `arr` array using the `filter()` method with a conditional statement that uses the double bangbang notation (`!!!`) to invert the truthiness of each element. **Latest Benchmark Result** The latest benchmark result shows the execution rates for both test cases on a Chrome 76 browser on a Mac OS X 10.14.3 system: | Test Name | Executions Per Second | | --- | --- | | Yes | 6870144.5 | | not not | 6792558.5 | The results suggest that the double bangbang notation (`!!!`) is slightly slower than the simple logical NOT operator (`!!`). However, it's essential to note that these results may vary depending on the specific use case and browser configuration. **Other Alternatives** There are other alternatives to achieve similar filtering effects in JavaScript: 1. Using `Array.prototype.map()` with a callback function: `test.map(x => (x === null) ? undefined : x);` 2. Using `Array.prototype.reduce()` with an accumulator function: `test.reduce((acc, x) => acc + (x === null ? 0 : 1), 0);` These alternatives may offer different performance characteristics and trade-offs compared to the double bangbang notation (`!!!`) or simple logical NOT operator (`!!`).
Related benchmarks:
array assignment vs array fill
var is a non-empty array
var is a non-empty array (v2)
var is a non-empty array (v3)
empty an array in JavaScript - splice vs setting length yonatan
Comments
Confirm delete:
Do you really want to delete benchmark?