測試主機(jī)配置: 為windows10 16核32G、Linux 2核2G、Linux 8核16G、
Cpu型號和核心數(shù),下面已經(jīng)列出。
在Windows10操作系統(tǒng)下 16核32G操作系統(tǒng)下
這里我們先給出結(jié)論
不同的主機(jī)配置,執(zhí)行結(jié)果是不一樣的,而且處理不同的任務(wù),結(jié)果也是不一樣的。所以并發(fā)執(zhí)行效率不一定比串行快。
package demo1;
public class ConcurrencyTest {public static void main(String[] args) throws InterruptedException {int[] arrCount=new int[]{10000,100000,10000000,100000000,1000000000};
for (int i = 0; i< arrCount.length; i++) {int count = arrCount[i];
System.out.println("并發(fā)累計(jì)執(zhí)行 :"+count+"次");
concurrency(count);
serial(count);
System.out.println("----------------------------");
}
}
private static void concurrency(int count) throws InterruptedException {long start= System.currentTimeMillis();
Thread thread=new Thread(new Runnable() {@Override
public void run() { int a=0;
for (long i = 0; i< count; i++) {a+=5;
}
}
});
thread.start();
int b=0;
for (long i = 0; i< count; i++) {b--;
}
thread.join();
long time = System.currentTimeMillis()-start;
System.out.println("concurrency :"+time+"ms,b="+b);
}
private static void serial(int count){long start= System.currentTimeMillis();
int a=0;
for (long i = 0; i< count; i++) {a+=5;
}
int b=0;
for (long i = 0; i< count; i++) {b--;
}
long time = System.currentTimeMillis() - start;
System.out.println("serial :"+time+"ms,b="+b+",a="+a);
}
}






你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
標(biāo)題名稱:并發(fā)執(zhí)行的效率一定比串行執(zhí)行快?-創(chuàng)新互聯(lián)
當(dāng)前URL:http://chinadenli.net/article8/cohgop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、手機(jī)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、外貿(mào)建站、做網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容