Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Classnames vs CLSX vs templateLiterals
Compare CLSX vs Classnames vs templateLiterals
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
classnames
2891837.2 Ops/sec
clsx
3925921.0 Ops/sec
My attempt using templateLiterals
3180644.8 Ops/sec
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')
My attempt using templateLiterals
const classname = (...args) => { let joined = ""; args.forEach((arg) => { if (!arg || typeof arg === 'boolean') { return; } if (typeof arg === "string") { joined += ` ${arg} `; } else if (typeof arg === "object") { if (arg?.join) { joined += arg.filter((v) => !!v).join(" "); } else { const keys = Object.keys(arg); keys.forEach(key => { if(!!arg[key]){ joined += ` ${key} ` } }) } } }); return joined; }; let result = classname(str, obj, arr, 'test classname')