Posted on 2008-09-08 10:05
dennis 閱讀(5849)
評(píng)論(5) 編輯 收藏 所屬分類:
java 、
my open-source
主要是比較offer跟poll兩個(gè)方法的性能,開N個(gè)線程,每個(gè)線程往隊(duì)列里寫或者取500個(gè)整數(shù)。
線程數(shù)
|
20
|
50
|
100
|
200
|
500 |
1000
|
LinkedBlockingQueue
|
15,0
|
31,15
|
32,16
|
63,32
|
203,47
|
563,110
|
ArrayBlockingQueue |
15,0
|
16,15
|
31,15
|
47,16
|
125,47
|
364,68
|
PriorityBlockingQueue |
78,78
|
172,188
|
360,422
|
813,969
|
3094,2641
|
6547,5453
|
逗號(hào)前的數(shù)字是offer測(cè)試花費(fèi)的時(shí)間,逗號(hào)后的數(shù)字是poll測(cè)試花費(fèi)的時(shí)間,單位毫秒。
結(jié)論:
1、ArrayBlockingQueue性能優(yōu)于LinkedBlockingQueue,但是LinkedBlockingQueue是無界的。
2、ArrayBlockingQueue和LinkedBlockingQueue的poll方法總是比offer方法快,并發(fā)越高,差距越大
3、ArrayBlockingQueue和LinkedBlockingQueue的性能遠(yuǎn)高于PriorityBlockingQueue,顯然優(yōu)先隊(duì)列在比較優(yōu)先級(jí)上的操作上耗費(fèi)太多
4、PriorityBlockingQueue的offer方法與poll方法的性能差距很小,基本維持在近似1:1