Sample insertion

Benchmark created on


Setup

function measureBox(content) {
	const box = document.createElement('div');
	box.textContent = content;
	document.body.appendChild(box);
	
	const height = box.getBoundingClientRect().height;
	document.body.removeChild(box);
	return height;
}

const lazyMeasureBox = createLazyMeasureBox();

function createLazyMeasureBox() {
	let boxRef;
	
	return (content) => {
		if (!boxRef) {
			boxRef = document.createElement('div');
			document.body.appendChild(boxRef);
			
			setTimeout(() => {
			if (boxRef) {
				document.body.removeChild(boxRef);
				boxRef = null;
			}
		});
		}
		
		boxRef.textContent = content;
		const height = boxRef.getBoundingClientRect().height;
		return height;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
1
measureBox('Sample Text');
ready
2
lazyMeasureBox('Sample Text');
ready

Revisions

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