• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 60785
190
  • 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: 3276
33
  • 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: 9378
181
  • 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: 3276
33
  • 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: 3276
33
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!