Re: Short-lived Objects - good or bad?
On Thu, 10 Apr 2008 05:39:30 -0700, Owen Jacobson wrote:
Out of curiousity, I benchmarked this a while ago on some of my own code
[0], first taking a version that allocated new objects relatively freely
and then writing a second version that performed the same operations but
preferred mutating existing objects.
Over ten million iterations, the difference in execution time was on the
order of hundreds of milliseconds - that is, utterly negligible.
-o
[0] Code extracted from an application whose performance I care about,
that is, real code and not code written for the benchmark.
I'd have to say that my experience has been different. I think it really
depends on the objects being created. A single new inside an inner loop
can be fine, but if that new results in many, many sub-objects being
created then you might have problems with it. A single visible new can
really translate into thousands of objects being created.
--
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>