import java.math.BigDecimal;
public class SingletonObjectPerformanceTest {
public static void main(String[] args) throws InterruptedException {
final Singleton singleton = new Singleton();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 800000; i++) {
Thread t = new Thread() {
@Override
public void run() {
callPrototype();
};
// call 싱글톤
public void callSingleton() {
singleton.test();
}
// call prototype
public void callPrototype() {
Prototype prototype = new Prototype();
prototype.test();
}
};
t.start();
t.join();
}
long endTime = System.currentTimeMillis();
double completeTime = endTime - startTime;
BigDecimal resuleTime = new BigDecimal(completeTime).divide(new BigDecimal(1000));
System.out.println("complete time : " + resuleTime.toString() + "초");
}
}
class Singleton {
public void test() {
System.out.println("singleton!!");
}
}
class Prototype {
public void test() {
System.out.println("prototype!!");
}
}