<script src="https://cdn.jsdelivr.net/npm/classnames@2.3.1/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clsx@1.1.1/dist/clsx.min.js"></script>
window.classNames('uu-foo', { 'uu-foo_bar': true, 'uu-foo_baz': false });
window.clsx('uu-foo', { 'uu-foo_bar': true, 'uu-foo_baz': false });
window.clsx({ 'uu-foo': true, 'uu-foo_bar': true, 'uu-foo_baz': false });
window.clsx('uu-foo', true && 'uu-foo_bar', false && 'uu-foo_baz');
window.clsx(['uu-foo', true && 'uu-foo_bar', false && 'uu-foo_baz']);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
classnames | |
clsx (classnames api) | |
clsx (objects) | |
clsx (arguments) | |
clsx (array) |
Test name | Executions per second |
---|---|
classnames | 3059318.8 Ops/sec |
clsx (classnames api) | 4519157.0 Ops/sec |
clsx (objects) | 4569702.5 Ops/sec |
clsx (arguments) | 4985847.0 Ops/sec |
clsx (array) | 4564981.0 Ops/sec |
Overview of the Benchmark
The provided benchmark compares the performance of two JavaScript libraries, Classnames and clsx, in different use cases. The benchmark tests how fast each library can execute its API.
Classnames and clsx Libraries
Options Compared in the Benchmark
?.
) in modern JavaScript to pass arguments as values that may or may not be present.Pros and Cons
Other Considerations
Alternatives
For most use cases, choosing between Classnames and clsx would depend on familiarity with each library, the need for specific features, and potential compatibility issues.