85 lines
1.7 KiB
JavaScript
85 lines
1.7 KiB
JavaScript
import { printCurrentStatus, printStatusHelperText } from "./compiler/utils.mjs";
|
|
|
|
function ifSingle(a) {
|
|
if (a[0] === 97 && a[1] === 97 && a[2] === 97 && a[3] === 97 && a.length === 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
function ifChain(a) {
|
|
if (a[0] === 97)
|
|
if (a[1] === 97)
|
|
if (a[2] === 97)
|
|
if (a[3] === 97)
|
|
if (a.length === 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
function ifSingleOptimized(a) {
|
|
if (a.length >= 4 && a[0] === 97 && a[1] === 97 && a[2] === 97 && a[3] === 97 && a.length === 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
function ifChainOptimized(a) {
|
|
if (a.length >= 4)
|
|
if (a[0] === 97)
|
|
if (a[1] === 97)
|
|
if (a[2] === 97)
|
|
if (a[3] === 97)
|
|
if (a.length === 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
function ifSingleOptimizedAlt(a) {
|
|
if (a.length >= 4 && a[0] == 97 && a[1] == 97 && a[2] == 97 && a[3] == 97 && a.length == 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
function ifChainOptimizedAlt(a) {
|
|
if (a.length >= 4)
|
|
if (a[0] == 97)
|
|
if (a[1] == 97)
|
|
if (a[2] == 97)
|
|
if (a[3] == 97)
|
|
if (a.length == 4) {
|
|
return 100
|
|
}
|
|
return 10
|
|
}
|
|
|
|
let paths = [
|
|
[97, 97, 97, 97],
|
|
[97, 97, 97, 97, 97],
|
|
[97, 97, 96, 97],
|
|
[97, 96, 97, 97],
|
|
[96, 97, 97, 97],
|
|
[],
|
|
[98],
|
|
[97, 97, 97],
|
|
[97, 97],
|
|
[97],
|
|
[97, 97, 96],
|
|
[97, 96],
|
|
[96],
|
|
]
|
|
|
|
let func1 = [ifSingle, ifChain, ifSingleOptimized, ifChainOptimized, ifSingleOptimizedAlt, ifChainOptimizedAlt];
|
|
for (let fun of func1) {
|
|
console.log('-- begin', fun.name)
|
|
for (var i = 0; i < 1000000; i++) {
|
|
paths.map(x => fun(x))
|
|
}
|
|
printCurrentStatus(fun);
|
|
}
|
|
printStatusHelperText()
|
|
|
|
|