Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Boolean vs String comparison for discriminated unions
(version: 0)
Comparing performance of:
rB vs rBStrict vs rStr vs rShortStr vs rObjB vs rObjBStrict vs rObjStr vs rObjProp vs rObjPropIn
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandoBoolean() { return !!(Math.floor(Math.random() * 2)); } function getRandoString() { return !!(Math.floor(Math.random() * 2)) ? 'accepted' : 'rejected'; } function getRandoShortString() { return !!(Math.floor(Math.random() * 2)) ? 'y' : ''; } var arrB = [...(new Array(1000))].map(v => getRandoBoolean()); var arrStr = [...(new Array(1000))].map(v => getRandoString()); var arrShortStr = [...(new Array(1000))].map(v => getRandoShortString()); var arrObjB = [...(new Array(1000))].map(v => getRandoBoolean() ? {ok : true ,b: 'value'}: {ok : false ,c: 'value'}); var arrObjStr = [...(new Array(1000))].map(v => getRandoBoolean() ? {ok : 'yes' ,b: 'value'}: {ok : 'no' ,c: 'value'}); var arrObjProp = [...(new Array(1000))].map(v => getRandoBoolean() ? {ok : true ,b: 'value'}: { c: 'value'});
Tests:
rB
const rB = arrB.reduce((acc, v) => v ? acc + 'yes' : acc + 'no', '');
rBStrict
const rBStrict = arrB.reduce((acc, v) => v === true ? acc + 'yes' : acc + 'no', '');
rStr
const rStr = arrStr.reduce((acc, v) => v === 'accepted' ? acc + 'yes' : acc + 'no', '');
rShortStr
const rShortStr = arrShortStr.reduce((acc, v) => v ? acc + 'yes' : acc + 'no', '_');
rObjB
const rObjB = arrObjB.reduce((acc, v) => v.ok ? acc + 'yes' : acc + 'no', '');
rObjBStrict
const rObjBStrict = arrObjB.reduce((acc, v) => v.ok === true ? acc + 'yes' : acc + 'no', '');
rObjStr
const rObjStr = arrObjStr.reduce((acc, v) => v.ok === 'yes' ? acc + 'yes' : acc + 'no', '');
rObjProp
const rObjProp = arrObjProp.reduce((acc, v) => v.ok ? acc + 'yes' : acc + 'no', '');
rObjPropIn
const rObjPropIn = arrObjProp.reduce((acc, v) => 'ok' in v? acc + 'yes' : acc + 'no', '');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
rB
rBStrict
rStr
rShortStr
rObjB
rObjBStrict
rObjStr
rObjProp
rObjPropIn
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):
It looks like you're sharing a JSON array of web browser information! Can I help you with something specific from this data, or would you like me to provide some insights or summaries?
Related benchmarks:
filter vs reduce vs difference
MapIncludes vs Find on collection
Array.prototype.some() vs. Filter vs. Array.prototype.indexOf()
Lodash difference vs Set & Filter 2
Some vs. Filter vs. indexOf vs. Map+Includes vs. Find
Comments
Confirm delete:
Do you really want to delete benchmark?