This is a classic java benchmarking issue. Hotspot/JIT/etc will compile your code as you use it, so it gets faster during the run.
Run around the loop at least 3000 times (10000 on a server or on 64 bit) first – then do your measurements.
More Related Contents:
- What is microbenchmarking?
- Is it possible to force an existing Java application to use no more than x cores?
- Benchmarking inside Java code
- When to use StringBuilder in Java [duplicate]
- The performance impact of using instanceof in Java
- Performance of Java matrix math libraries? [closed]
- Fastest way to iterate over all the chars in a String
- How do I speed up the gwt compiler?
- Performance of StringTokenizer class vs. String.split method in Java
- Is there any performance reason to declare method parameters final in Java?
- Why is System.out.println so slow?
- Android RecyclerView Scrolling Performance
- Java HashMap performance optimization / alternative
- Does variable = null set it for garbage collection
- Garbage collection behaviour for String.intern()
- Android – Prevent white screen at startup
- Java XPath (Apache JAXP implementation) performance
- Most efficient way of converting String to Integer in java
- Should try…catch go inside or outside a loop?
- Java thread creation overhead
- How to speed up Java VM (JVM) startup time?
- Hash Set and Array List performances
- Java: how much time does an empty loop use?
- Java application profiling
- ‘ … != null’ or ‘null != ….’ best performance?
- HQL joined query to eager fetch a large number of relationships
- Theoretical limit for number of keys (objects) that can be stored in a HashMap?
- Recycler view – resizing item view while scrolling (for carousel like effect)
- Measuring time spent on GC
- Try Catch Performance Java