Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Boolean vs double bang !!
(version: 0)
Comparing performance of:
Boolean vs Double bang !!
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var newArr = [11298, 64188, false, '', -17539, -2718, -81300, -93173, 12150, -23314, -90890, 10472, 68323, null, 14756, 23838, 44324, 8742, -14019, 850, 75308, 56916, -9163, -5720, -74582, 14163, -38494, 5965, 61498, 96239, 22710, -74672, 65462, 5866, 95287, -99185, -87437, -65516, 87094, -24801, 44795, 82241, -58676, -88510, 33894, 92451, -65650, 89705, -40431, 15336, 34274, -68818, -58107, 59473, 54784, 15912, -51295, 98932, -70544, -61433, -80291, -3195, -27401, -89871, 32656, 79579, 47926, -69927, -76320, 62505, null, -33635, 36563, 84709, 73487, -1266, 64863, -86546, -4595, 33695, -18952, 4906, -14988, -90722, 28588, -53613, 58586, 72780, -57395, 91036, 66411, 82860, -93967, -90093, 83360, -62200, 6289, -54882, -40122, -65505, 30931, -93352, 30424, -12587, 1.8566900229637684, 1.3011419549756973, 1.1708070924467107, 1.1819141247478844, 1.4578638598859297, undefined, NaN, undefined, 1.1219243130494703, 1.698862057601821, 1.2357960424915777, 1.6060255866350979, 1.8577522621138371, 1.1832093514225788, 1.7426406496354048, 1.533257615040655, 1.5262907371593901, 1.1065375905007233, 1.716525097644193, 1.6130346286949768, 1.1618851436955837, 1.842052624586361, 1.3325571621599352, 1.2117505914206794, 1.5448256621289034, 1.9784677360157352, 1.453593375677712, 1.8737035178512615, 1.3963905343775227, 1.1844284040348567, 1.1752619028897677, 1.4586216763191184, 1.643308280549214, 1.9354515367855045, 1.7826635257999848, 1.3552860607477877, 1.8330370522617598, 1.6112899872390167, 1.6654639110922305, 1.0553428195648753, 1.2764309508299496, 1.479479693956518, 1.724839630514982, 1.376958088803886, 1.4095892542209163, 1.0915209200309886, 1.1283919063449177, 1.087726847164952, 1.6050053445118588, 1.184795455938699, 1.8095744228621569, 1.2577660608553072, 1.5751391585285301, 1.8566900229637684, -1.3011419549756973, -1.1708070924467107, -1.1819141247478844, -1.4578638598859297, -1.1219243130494703, 1.698862057601821, -1.2357960424915777, 1.6060255866350979, 1.8577522621138371, -1.1832093514225788, 1.7426406496354048, 1.533257615040655, 1.5262907371593901, -1.1065375905007233, 1.716525097644193, 1.6130346286949768, -1.1618851436955837, 1.842052624586361, -1.3325571621599352, -1.2117505914206794, 1.5448256621289034, 1.9784677360157352, -1.453593375677712, 1.8737035178512615, -1.3963905343775227, -1.1844284040348567, -1.1752619028897677, -1.4586216763191184, 1.643308280549214, 'apendix', 1.7826635257999848, -1.3552860607477877, 'eye', 1.6112899872390167, 1.6654639110922305, -1.0553428195648753, -1.2764309508299496, -1.479479693956518, 1.724839630514982, -1.376958088803886, -1.4095892542209163, -1.0915209200309886, -1.1283919063449177, -1.087726847164952, 1.6050053445118588, -1.184795455938699, 1.8095744228621569, -1.2577660608553072]
Tests:
Boolean
const a1 = newArr.map((v) => Boolean(v))
Double bang !!
const b1 = newArr.map((v) => !!v)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Boolean
Double bang !!
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Boolean
2916253.8 Ops/sec
Double bang !!
2908083.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is defined in JSON format, which includes: * `Script Preparation Code`: This is a JavaScript snippet that initializes an array (`newArr`) with various values. * `Html Preparation Code`: This is empty, indicating that no HTML code needs to be prepared before running the benchmark. * `Benchmark Definitions`: These are two individual test cases: * `"const a1 = newArr.map((v) => Boolean(v))"`: Tests the performance of converting an array element to a boolean value using the `Boolean()` function. * `"const b1 = newArr.map((v) => !!v)"`: Tests the performance of converting an array element to a boolean value using the double-bang operator (`!!`). **Individual Test Cases** Each test case includes: * `Benchmark Definition`: The specific JavaScript code being tested. * `Test Name`: A descriptive name for each test case. **Comparison** The benchmark compares the performance of two approaches: 1. `Boolean(v)`: This method creates a new boolean value based on the input value. 2. `!!v`: This method uses the double-bang operator to convert the input value to a boolean value. The double-bang operator first converts the value to a number and then checks if it's zero. This approach is faster because it avoids creating an intermediate boolean object. **Pros and Cons** * **Boolean(v)**: * Pros: Clearer intent, better maintainability. * Cons: Creates an intermediate boolean object, which can be slower due to memory allocation and garbage collection. * `!!v`: * Pros: Faster, as it avoids creating an intermediate object. * Cons: Less readable, and its behavior might not be immediately clear to developers. In summary, the benchmark tests the performance of two different approaches to converting array elements to boolean values. The `!!v` approach is faster but less readable, while `Boolean(v)` creates a clearer intent but may be slower due to memory allocation.
Related benchmarks:
String from Charcode test
String from Charcode test with ...
MinMax comparison 2
Array IndexOf vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?