test class names concat

Benchmark created on


Setup

function toVal(mix) {
	var k, y, str='';

	if (typeof mix === 'string' || typeof mix === 'number') {
		str += mix;
	} else if (typeof mix === 'object') {
		if (Array.isArray(mix)) {
			for (k=0; k < mix.length; k++) {
				if (mix[k]) {
					if (y = toVal(mix[k])) {
						str && (str += ' ');
						str += y;
					}
				}
			}
		} else {
			for (k in mix) {
				if (mix[k]) {
					str && (str += ' ');
					str += k;
				}
			}
		}
	}

	return str;
}

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

function clsxMy(...args) {
  return args.filter(Boolean).join(' ')
}


Test runner

Ready to run.

Testing in
TestOps/sec
clsx
clsx('class1', 'class2', 'class3', 'class1', 'class2', 'class3', 'class1', 'class2', 'class3')
ready
clsxMy
clsxMy('class1', 'class2', 'class3', 'class1', 'class2', 'class3', 'class1', 'class2', 'class3')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.