Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Classnames vs CLSX vs Template Literals 2/28/2023
Compare CLSX vs Classnames vs an own implementation of creating a template string
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
classnames
1499915.2 Ops/sec
clsx
5946895.0 Ops/sec
Template Literals
3444327.2 Ops/sec
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`