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 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser:
Firefox 141
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
classnames
1612771.4 Ops/sec
clsx
2365382.0 Ops/sec
Template Literals
2650963.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`