ArrayList vs LinkedList sorting speed?
According to: https://stackoverflow.com/questions/8069370/is-an-arraylist-or-a-linkedlist-better-for-sorting:
Doesn't seem to be that impressive of a difference when measuring. Why?
9 Replies
⌛
This post has been reserved for your question.
Hey @Steadhaven! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
what? yes it is
java itself is just not accurate for benchmarking because of gc and jit
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
>well written code btw!
I can't take the credit :) I just found it and thought it was a nice code, but wondered why both ArrayList and LinkedList were so close :)
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
this depends on the os, and it's not a java problem. you also dont need to have perfect real world accuracy for benchmarking, just a constant interval between two points in time
If you want to benchmark, use JMH. Second, yes like bogrel said, arraylist is preffered in 99% of cases.
Benchmarks in Java are hard to do. So don't just slap some nanotimes here and there and expect it to be correct. It takes a while for the JVM to optimize code etc
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.