We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Again, there is no difference. You don't call a method when accessing the length of the array. You just read an internal field. Even if you called a method, the difference would be negligible with current JVMs. And also methods like length() will get inlined by JVM for optimization purpose.
I did 100K iterations to compare both performance on my
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.2) (7u65-2.5.2-3~14.04)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
I got:
Average diff: 3 nano secs|| using length() is better: 0.5892|| without length() is better: 0.4108
I did run mutiple times, sometimes, I see average diff could go up to three digits, negative or positive. It is not replyable.
To sum up, I don't think you can say either way is definitely better. To me it makes no difference, even for high frequency trading, no matter 100 ns or 3 ns, that light travels 1 metre in a vacuum. On the other side, you do care about ns level deterministic latency, you might not use java. lol
Tree: Huffman Decoding
You are viewing a single comment's thread. Return to all comments →
Again, there is no difference. You don't call a method when accessing the length of the array. You just read an internal field. Even if you called a method, the difference would be negligible with current JVMs. And also methods like length() will get inlined by JVM for optimization purpose.
I did 100K iterations to compare both performance on my java version "1.7.0_65" OpenJDK Runtime Environment (IcedTea 2.5.2) (7u65-2.5.2-3~14.04) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
I got:
Average diff: 3 nano secs|| using length() is better: 0.5892|| without length() is better: 0.4108
I did run mutiple times, sometimes, I see average diff could go up to three digits, negative or positive. It is not replyable.
To sum up, I don't think you can say either way is definitely better. To me it makes no difference, even for high frequency trading, no matter 100 ns or 3 ns, that light travels 1 metre in a vacuum. On the other side, you do care about ns level deterministic latency, you might not use java. lol
public static void main(String [] args){ long startTime,endTime; String s ="Un lago en el cielo quiero ser suave para evitar tu dureza apago tu fuego enciende" +"mi agua puede que no haya certezas Vamos despacio para el tiempo es arena en mis manos sé por tus marcas" +"cuanto has amado más de lo que prometiste";