Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Classnames vs CLSX vs Template Literals 2/28/2023
(version: 0)
Compare CLSX vs Classnames vs an own implementation of creating a template string
Comparing performance of:
classnames vs clsx vs Template Literals
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/classnames/2.3.2/index.min.js'></script> <script src='https://unpkg.com/clsx@1.2.1/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
const result = window.classNames(str, obj, arr, 'test classname')
clsx
const result = window.clsx(str, obj, arr, 'test classname')
Template Literals
const reduced = (o) => Object.entries(o).reduce((acc, cur) => { if (cur[1]) acc.push(cur[0]); return acc; }, []).join(' '); const result = `${str} ${reduced(obj)} ${arr.join(' ')} test classname`
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
classnames
clsx
Template Literals
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
classnames
1612771.4 Ops/sec
clsx
2365382.0 Ops/sec
Template Literals
2650963.2 Ops/sec
Related benchmarks:
trim vs lodash/fp
trim-loadsh vs native-trim
Lodash some vs Native some
comparsions force straight vs ideomatic
Lodash.get vs Property dot notation with ?
Comments
Confirm delete:
Do you really want to delete benchmark?