Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.NumberFormat;
- public class Main{
- public static void main(String[] args) {
- long startTime = 0, endTime = 0;
- Child c = new Child();
- Parent p = c;
- Inter f = c;
- final long SIZE = 1000000000L;
- NumberFormat format = NumberFormat.getInstance();
- startTime = System.nanoTime();
- System.out.print("Direct refference => ");
- for(int i=0; i<= SIZE; i++){
- c.inc(i);
- }
- endTime = System.nanoTime();
- System.out.println(format.format(endTime-startTime));
- startTime = System.nanoTime();
- System.out.print("Parent refference => ");
- for(int i=0; i<= SIZE; i++){
- p.inc(i);
- }
- endTime = System.nanoTime();
- System.out.println(format.format(endTime-startTime));
- startTime = System.nanoTime();
- System.out.print("Interface refference => ");
- for(int i=0; i<= SIZE; i++){
- f.inc(i);
- }
- endTime = System.nanoTime();
- System.out.println(format.format(endTime-startTime));
- startTime = System.nanoTime();
- System.out.print("Static refference => ");
- for(int i=0; i<= SIZE; i++){
- Child.incS(i);
- }
- endTime = System.nanoTime();
- System.out.println(format.format(endTime-startTime));
- }
- }
- interface Inter {
- public long inc(long l);
- }
- class Child extends Parent implements Inter {
- public long inc(long l){
- return l+1;
- }
- public static long incS(long l){
- return l+1;
- }
- }
- class Parent {
- public long inc(long l){
- return l+1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement