測試你得有個(gè)對(duì)比吧,和promise對(duì)比,async也不是為了性能吧,應(yīng)該是讓你可以像寫同步代碼一樣寫異步代碼;至于x1的執(zhí)行時(shí)間遠(yuǎn)遠(yuǎn)大于其他時(shí)間,你每次循環(huán)做的事情一樣,我猜v8的強(qiáng)大緩存能力幫你優(yōu)化了functionsleep(time){returnnewPromise(function(resolve,reject){setTimeout(function(){resolve()},time)})}functiontestPromise(time){letstr=`testpromise,${time}s`console.time(str)sleep(time).then(()=>{console.timeEnd(str)})}asyncfunctiontestAsync(time){letstr=`testawait,${time}s`console.time(str)awaitsleep(time)console.timeEnd(str)}asyncfunctiontests(tiemList){for(leti=0,len=tiemList.length;ilettime=tiemList[i]testAsync(time)//等待上一布完成awaitsleep(time+500)testPromise(time)//等待上一布完成awaitsleep(time+500)}console.log('測試完成')}lettiemList=[200,600,1000,1400,1800,2200]tests(tiemList)