Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
manual vs filter
(version: 0)
Comparing performance of:
classnames vs classnames flex
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function classnames2(a, b) { return a ? (b ? `${a} ${b}` : a) : b || ''; } function classnames3(a, b, c) { return a ? b ? c ? `${a} ${b} ${c}` : `${a} ${b}` : c ? `${a} ${c}` : a : classnames2(b, c); } function classnamesFlex(...classes) { return classes.filter(Boolean).join(' '); } // explicitly handling 2 arguments handles most of our use cases efficiently function classnames(a, b, c) { const numArgs = arguments.length; if (numArgs === 1) { return a || ''; } else if (numArgs === 2) { return classnames2(a, b); } else if (numArgs === 3) { return classnames3(a, b, c); } else { return classnamesFlex.apply(null, arguments); } }
Tests:
classnames
classnames(null, "a");
classnames flex
classnamesFlex(null, "a");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
classnames
classnames flex
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!
Related benchmarks:
Conditionals (if-else, ternary, switch, object-function, object-plain,object-get)
Conditionals (if-else, ternary, switch, object-function, object-plain) with last evaluation v3 (with obj-get!)
join vs trim vs filter
join vs string + trim vs filter + join
Filter Boolean vs. Custom Function
Comments
Confirm delete:
Do you really want to delete benchmark?