clsx icon indicating copy to clipboard operation
clsx copied to clipboard

Could default exported function perform a tiny bit better?

Open realamirhe opened this issue 5 years ago • 2 comments

export default function () {
- 	var i=0, tmp, x, str='';
+ 	var tmp, x, len=arguments.length, str='', i=0;
-	while (i < arguments.length) {
+	while (i < len) {
		if (tmp = arguments[i++]) {
			if (x = toVal(tmp)) {
				str && (str += ' ');
				str += x
			}
		}
	}
	return str;
}

Benchmark on only string concatenation shows an increase of about 1,000,000 operation/sec. Note: I got benchmark results only in node, in a really inaccurate way. but theoretically, it must increase the performance.

realamirhe avatar Oct 05 '20 17:10 realamirhe

Hey, thanks!

This is already done in #26 – I haven't been able to setup a clean bench environment to test this out yet. Caching a foo.length used to not matter, but it may very well matter once again.

It's on my TODO list to go through these PRs.

lukeed avatar Oct 05 '20 17:10 lukeed

Any news on this?

hood avatar Apr 17 '22 23:04 hood

This was addressed & merged in the linked PR. Thanks

lukeed avatar Dec 29 '23 18:12 lukeed