jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
const instructions = new Map([
['movr', 10],
['movv', 11],
['add', 20],
['sub', 21],
['push', 30],
['pop', 31],
['jp', 40],
['jl', 41],
['call', 42],
['ret', 50],
['print', 60],
['halt', 255],
])
const instructionsObj = {
'movr': 10,
'movv': 11,
'add': 20,
'sub': 21,
'push': 30,
'pop': 31,
'jp': 40,
'jl': 41,
'call': 42,
'ret': 50,
'print': 60,
'halt': 255,
}
///////////// FNS
const parseLine_better = (line) => {
const tokens = line.split(/\s+/g)
const parsed_tokens = []
for(let token in tokens) {
const clean_token = token.replace(",", "").trim().toLowerCase()
if (clean_token.length > 0) {
const instruction = instructions.get(clean_token)
let t = clean_token
if (instruction) t = instruction
else if (clean_token.includes("R")) t = clean_token.slice(1)
else parsed_tokens.push(parseInt(t))
}
}
return parsed_tokens
}
const parseLine2 = (line) => {
return line.split(/\s+/g)
.map(token => token.replace(",", "").trim().toLowerCase())
.filter(token => token.length > 0)
.map(token => {
const instruction = instructions.get(token)
if (instruction) return parseInt(instruction)
if (token.includes("R")) return parseInt(token.slice(1))
return parseInt(token)
})
}
const parseLine = (line) => {
return line.split(/\s+/g)
.map(token => token.replace(",", "").trim().toLowerCase())
.filter(token => token.length > 0)
.map(token => {
const instruction = instructions.get(token)
if (instruction) return instruction
if (token.includes("R")) return token.slice(1)
return token
})
.map(token => parseInt(token))
}
const parseLineOgObj = (line) => {
return line.split(/\s+/g)
.map(token => token.replace(",", "").trim().toLowerCase())
.filter(token => token.length > 0)
.map(token => {
const instruction = instructionsObj[token]
if (instruction) return instruction
if (token.includes("R")) return token.slice(1)
return token
})
.map(token => parseInt(token))
}
const parseLine_better_obj = (line) => {
const tokens = line.split(/\s+/g)
const parsed_tokens = []
for(let token in tokens) {
const clean_token = token.replace(",", "").trim().toLowerCase()
if (clean_token.length > 0) {
const instruction = instructionsObj[clean_token]
let t = clean_token
if (instruction) t = instruction
else if (clean_token.includes("R")) t = clean_token.slice(1)
else parsed_tokens.push(parseInt(t))
}
}
return parsed_tokens
}
const asm = `MOVV R0, 10
CALL 6
HALT
PUSH R0
MOVV R0, 0
MOVV R1, 1
MOVV R3, 1
PRINT R1
MOVR R2, R0
ADD R2, R1
PRINT R2
MOVR R0, R1
MOVR R1, R2
MOVV R2, 1
ADD R3, R2
POP R2
PUSH R2
JL R3, R2, 19
POP R0
RET`
Ready to run.
Test | Ops/sec | |
---|---|---|
BETTER LINE |
| ready |
LINE 2 |
| ready |
LINE OG |
| ready |
BETTER LINE WITH OBJ |
| ready |
LINE OG with OBJ |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.