This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayDeque vs LinkedList as Queue  RSS feed

 
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I found next line in ArrayDeque javadoc:

"This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue".

So, is there a way to check this statement?

System.currentTimeMillis() doesn't work at all: two runs in a row and two opposite results.






 
Marshal
Posts: 58393
178
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But System.currentTimeMillis() is working. That is a typical result when you try performance speeds. Before you try any timings, make sure to run several runs so not less than 10⁴ operations are done in succession. That will instigate the Just in Time compilation. Then take several different timings because it is quite common for apparently opposite timings to occur like that. Also alternate them: sometimes run AD first and sometimes LL.
 
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code so we can run some tests?
 
Saloon Keeper
Posts: 8601
161
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use a microbenchmark framework like JMH. It deals with very complex performance testing issues that require deep understanding of the JVM. Check out the samples to get an idea.
 
Oleksii Movchan
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Can you post your code so we can run some tests?



To my surprise, when I deleted other methods from my TimeCounter class, it somehow started to run as it should = ArrayDeque is almost always faster than LinkedList.
Probably the problem was that before calculating AD vs LL, in the same code I was calculating ArrayList vs LinkedList, and it would made impact on the performance.

Could you help me please with the file attachment procedure? I can't do it neither with *.java files, nor *.zip
And can't find [spoiler] button to post it as a code.
 
Norm Radder
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a button above the input box labeled: Code
Post the code via copy and paste, select it and press the Code button.
And it should look like this:
 
Oleksii Movchan
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw it, but there are three files so I think it's a bit strange to post it this way without spoilers. Anyway, here they are.





 
Norm Radder
Rancher
Posts: 2862
32
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I see is the autoboxing of the double to Double:

Create a Double object to use instead using a double.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!