I've read up on and used AffineTransform for a lot of things in my code, but I've never been clear on what happens behind the scenes.
Particularly, I'm interested in it's performance.
For translation, would it be quicker to apply an AffineTransform to a Path2D through it's transform(at) method, or create another Path2D object with new coordinates and let Java do garbage collection on the old one? Does AffineTransform create another object in it's process of translation?
I figured I might get a reply like that, after thinking about it a bit more.
I still have a hard time comprehending the speed at which a computer executes.
And doing a performance test at this point would be a waste of my time, I think.
Thanks for the reply though. I'll try and keep in mind how easy it is for Java to create objects.
Caleb Kemper wrote:I still have a hard time comprehending the speed at which a computer executes.
Yes, that's quite common. Look at it this way: let's suppose you have a 4 GHz system (a reasonable guess at this time). That means it can execute 4 billion operations in one second. Now let's guess that it might take 1000 machine operations to create an object. That means you can create 4 million objects in one second. Once you start doing back-of-the-envelope calculations like that, you tend not to do as much premature optimization.
And when it comes down to choosing between using a suitable built-in class or method versus writing my own customized version, my first choice would be to use the built-in code. For one thing, life is too short to spend it rewriting code which is already available for use, and for another, the people who wrote the built-in code have probably done a better job than I would do with my customized version. Sure, it's possible that I might write a specialized version which works better for me than the generalized built-in code, but I'm only going to do that if I actually need it to work better.