lukeed / clsx

A tiny (239B) utility for constructing `className` strings conditionally.
MIT License
8.08k stars 141 forks source link

feat: simplify isArray: clsx.apply #55

Closed yangg closed 1 year ago

lukeed commented 1 year ago

While less code, this is almost certainly slower. Function lookups/executions aren’t free. Will perf test when have some spare time

lukeed commented 1 year ago

Confirmed. On Node 18.12.1, these are the Array-related benchmark results:

# Arrays
  clsx         x 10,514,890 ops/sec ±0.14% (101 runs sampled)
  clsx (apply) x  9,399,861 ops/sec ±0.18% (99 runs sampled)

# Nested Arrays
  clsx         x 8,326,852 ops/sec ±0.39% (98 runs sampled)
  clsx (apply) x 6,989,572 ops/sec ±0.14% (99 runs sampled)

# Nested Arrays w/ Objects
  clsx         x 8,458,578 ops/sec ±0.17% (97 runs sampled)
  clsx (apply) x 7,853,655 ops/sec ±0.17% (100 runs sampled)

# Mixed
  clsx         x 9,369,221 ops/sec ±0.29% (100 runs sampled)
  clsx (apply) x 8,903,049 ops/sec ±0.13% (100 runs sampled)

# Mixed (Bad Data)
  clsx         x 3,654,474 ops/sec ±0.42% (97 runs sampled)
  clsx (apply) x 3,554,495 ops/sec ±0.33% (100 runs sampled)

The clsx (apply) – which is this PR – is slower in every suite

Thank you for the PR though! Was a good idea :D