Two Column CSV/TSV Parser

Benchmark created on


Setup

const lineSep = "\n"
const fieldSep = ","
const text = `10,AAA
10,BBB
10,CCC
5,ddd
5,eee
1,fff`

let out = []

Test runner

Ready to run.

Testing in
TestOps/sec
String.split()
text.split(lineSep).forEach(line => {
	if (line.length !== 0) {
		out.push(line.split(fieldSep))
	}
})

ready
String Tokenizer
let i = 0
let start = 0
let weight = ""
for (const c of text) {
	if (c === fieldSep) {
		weight = text.substring(start, i)
		start = i+1
	}
	else if (c === lineSep) {
		out.push([weight, text.substring(start, i)])
		start = i+1
	}
	i++
}
if (start !== i) {
	out.push([weight, text.substring(start, i)])
}

ready

Revisions

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