Why are the dots slow

I need to pass x / y. I just used java.awt.Point. I do this a lot, given the nature of the application, but less than regular arrays. I also tried to create my own "FastPoint", which is just int x / y and a very simple class constructor, which is also very slow.

Time is in milliseconds.

java.awt.Point: 10374
FastPoint: 10032
Arrays: 1210

public class FastPoint {  

    public int x;  
    public int y;  

    public FastPoint(int x, int y) {  
            this.x = x;  
            this.y = y;  
    }
}

Jvisualvm says Point (either awt or my own) uses tons of memory compared to a simple int [] array.

, um, ? Point? int ( ), , , - ?

:

for (int i = 0; i < maxRuns; i++) { 
    point = new Point(i,i); 
}

for (int i = 0; i < maxRuns; i++) { 
    a[0] = i; a[1] = i; 
}
+5
1

: , . , , :

: 19 nano seconds/iteration

: 47 nano /

, , , (JIT, -, ).

, cpu , .

+9

All Articles