Java Programming

loop 안과 밖에서의 obj.class.getName() 사용 performance 비교

tomato13 2009. 6. 14. 11:52

static long l_test6_start;

static long l_test6_end;

static void test6() {

int l_cnt = 0;

l_test6_start = System.currentTimeMillis();

for(; l_cnt<1000; l_cnt++) {

System.out.println(Test.class.getName());

}

l_test6_end = System.currentTimeMillis();

}

static long l_test7_start;

static long l_test7_end;

static void test7() {

int l_cnt = 0;

String l_str = Test.class.getName();

l_test7_start = System.currentTimeMillis();

for(; l_cnt<1000; l_cnt++) {

System.out.println(l_str);

}

l_test7_end = System.currentTimeMillis();

}

private static int tc9() {

test6();

test7();

System.out.println("l_test6_start: " + l_test6_start);

System.out.println("l_test6_end: " + l_test6_end);

System.out.println("l_test7_start: " + l_test7_start);

System.out.println("l_test7_end: " + l_test7_end);

return 1;

}


=>


l_test6_start: 1244947661702

l_test6_end: 1244947661764     // 62 msec 차이를 보임

l_test7_start: 1244947661764

l_test7_end: 1244947661796    // 32 msec 차이를 보임