On Fri, 12 May 2006, Lenny Rachitsky wrote:
I'm trying to improve the performance of some code, and I've found that a lot of the inefficiencies I have are caused by a large number of DateTime object creations. I would like to update the code to create the object only once, and update it with different epoch times, instead of creating a new object ->from_epoch each time. Is this possible? To set the epoch time of an existing object?
While there's no API for this, it wouldn't be any more efficient if there were. The reason object creation is slow is that there's a bunch of stuff it does to figure out bits of data needed internally. Whenever you set a component of a DateTime object, it goes through the same computations for the new DateTime. Mutating an object, either via set() or math is fundamentally the same as creating a new object.
If you have to create lots of objects from _different_ epochs, it's probably going as fast as it can. However, if you're likely to see the same epoch repeatedly, you could do some sort of memoization and see a speed boost.
-dave /*=================================================== VegGuide.Org www.BookIRead.com Your guide to all that's veg. My book blog ===================================================*/