手機(jī)網(wǎng)站建設(shè)怎么樣網(wǎng)絡(luò)媒體推廣方案
最佳方式是運(yùn)行10次,取平均數(shù),用時(shí)秒數(shù)顯示3位小數(shù)。
因?yàn)榈谝淮未蜷_(kāi),可能CPU還沒(méi)優(yōu)化好,多次取平均,比較準(zhǔn)確
第1次共10次,用時(shí)3秒,平均3秒
第2次共10次,用時(shí)4秒,平均3.5秒
我主要是研究相同的函數(shù),相同的 算法,不同編程語(yǔ)言,哪個(gè)運(yùn)行更快
問(wèn): 為啥要找7的倍數(shù)?
比如10億次加法,40種編程語(yǔ)言比較哪個(gè)快一點(diǎn)
就是找個(gè)算法,比較不同編程語(yǔ)言速度相差多少
比如10億次加法,40種編程語(yǔ)言比較哪個(gè)快一點(diǎn)
比如VB6 2秒,易語(yǔ)言36秒,LUA 70秒,按鍵要1-5萬(wàn)秒
js網(wǎng)頁(yè)測(cè)試:
<body>
Javascript-10億次求余數(shù)計(jì)算測(cè)試,7的整數(shù)個(gè)數(shù)有多少?</br><script type='text/javascript'>
var count=1000*1000*1000;
var testcount=10;
var alltime=0;
var t=0;var int = self.setInterval("clock()", 1);
function clock() {t += 1;if (t == 1) {document.write("Javascript-10億次求余數(shù)計(jì)算測(cè)試,7的整數(shù)個(gè)數(shù)有多少?測(cè)試次數(shù):" + testcount + "</br></br>");}var c = 0;var begin = new Date();for (var i = 0; i < count; i++) {if (i % 7 == 0) c += 1;}var end = new Date();var usedtime = end - begin;alltime = alltime + usedtime;document.write("第" + t + "次/" + testcount + ",JS用時(shí)=" + usedtime + "毫秒,找到數(shù)量:" + c + "</br>");if (t == testcount) {int = window.clearInterval(int);document.write("</br>測(cè)試" + testcount + "次,總用時(shí)=" + (alltime / 1000).toFixed(4) + "秒,平均速度" + (alltime / 1000 / testcount).toFixed(4) + "秒");}} //function clock</script>
</body>