Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Classnames vs CLSX vs custom using reduce
(version: 0)
Compare CLSX vs Classnames vs custom implementation
Comparing performance of:
classnames vs clsx vs Custom implementation using reduce
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/classnames/2.2.6/index.min.js'></script> <script src='https://unpkg.com/clsx@1.1.0/dist/clsx.min.js'></script>
Script Preparation code:
var str = 'style'; var obj = { 'style-2': true, 'style-3': false, 'style-4': true, } var arr = ['style-5', 'style-6']
Tests:
classnames
let result = window.classNames(str, obj, arr, 'test classname')
clsx
let result = window.clsx(str, obj, arr, 'test classname')
Custom implementation using reduce
function maybeJoin(a,b) { return b ? a + " " + b : a; } function customCn(...args) { return args.reduce((acc, curr) => { if (!curr) return acc; if (typeof curr === "string") { return maybeJoin(acc,curr); } if (Array.isArray(curr)) { return maybeJoin(acc, curr.filter(Boolean).join(" ")); } if (typeof curr === "object") { return maybeJoin(acc, Object.keys(curr).filter((key) => key && curr[key]).join(" ")); } return acc; }, ''); } let result = customCn(str, obj, arr, 'test classname');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
classnames
clsx
Custom implementation using reduce
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!
Comments
Confirm delete:
Do you really want to delete benchmark?