Destructre assignment vs direct access

Benchmark created on


Setup

const headers = [
	['Set-Cookie', 'key=value'],
	['Set-Cookie', 'key2=value2'],
	['Set-Cookie', 'key3=value3'],
	['Set-Cookie', 'key4=value4'],
	['Set-Cookie', 'key=value'],
	['Set-Cookie', 'key2=value2'],
	['Set-Cookie', 'key3=value3'],
	['Set-Cookie', 'key4=value4'],
]

const headersObj = new Headers(headers)

const counters = {
	destructuring: 0,
	direct: 0
}

function incDest(value) {
	counters.destructuring += value
}

function incDir(value) {
	counters.direct += value
}

Teardown

console.log(counters.destructuring, counters.direct)
counters.destructuring = 0
counters.direct = 0

Test runner

Ready to run.

Testing in
TestOps/sec
Destructuring Array
for(const header of headers) {
	const [key, value] = header
	
	incDest(value.length)
}
ready
Direct access Array
for(const header of headers) {
	const key = header[0]
	const value = header[1]

	incDir(value.length)	
}
ready
Destructuring Headers
for(const header of headersObj) {
	const [key, value] = header
	
	incDest(value.length)
}
ready
Direct access Headers
for(const header of headersObj) {
	const key = header[0]
	const value = header[1]

	incDir(value.length)	
}
ready

Revisions

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