let arr = [132,4,5,6,'23',34,'555'];
function addInt(a,b){ return a + b };
function addStr(a,b) { return a + b };
function addAll(a,b) { return a + b };
let time = 200000;
function runSum0() {
for (var i = 0; i < time; i++) {
let k = arr[i % arr.length];
if (typeof k == 'string') {
//console.log('str',addStr(k, k));
addStr(k, k)
} else {
//console.log('int:',addInt(k, k));
addInt(k, k)
}
}
}
function runSum1() {
for (var i = 0; i < time; i++) {
let k = arr[i % arr.length];
//console.log('--:',addInt(k, k));
addAll(k, k)
}
}
let t1 = Date.now();
runSum0();
console.log("runTime1", (Date.now() - t1));
t1 = Date.now();
runSum1();
console.log("runTime2", (Date.now() - t1));
VM364:27 runTime1 6
VM364:30 runTime2 7
undefined
time = 10000000
t1 = Date.now();
runSum0();
console.log("runTime1", (Date.now() - t1));
t1 = Date.now();
runSum1();
console.log("runTime2", (Date.now() - t1));
VM385:4 runTime1 47
VM385:7 runTime2 167
undefined
time = 100000000;
t1 = Date.now();
runSum0();
console.log("runTime1", (Date.now() - t1));
t1 = Date.now();
runSum1();
console.log("runTime2", (Date.now() - t1));
VM389:4 runTime1 449
VM389:7 runTime2 1616
v8优化回退测试
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...