Using this test:
@Test
public void loadTestCloner() {
Calendar cal = GregorianCalendar.getInstance();
long timer = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
Cloner c1 = new Cloner();
Calendar x = c1.deepClone(cal);
}
System.out.println("total time for new one each time: [" + (System.currentTimeMillis() - timer) + "]ms");
long timer2 = System.currentTimeMillis();
Cloner c2 = new Cloner();
for (int i = 0; i < 100000; i++) {
Calendar x = c2.deepClone(cal);
}
System.out.println("total time for reused one: [" + (System.currentTimeMillis() - timer2) + "]ms");
}
With Calander results:
- total time for new one each time: [644]ms
- total time for reused one: [39]ms
And using our complex object:
- total time for new one each time: [9585]ms
- total time for reused one: [416]ms
And just using 1 object and using a "out of timer" Cloner:
- total time for new one each time: [13]ms
- total time for reused one: [0]ms
So I conclude that, while not a lot of time, and since it is Threadsafe, it is good to make this once and reuse it.