wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Inner workings of AffineTransform Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Inner workings of AffineTransform" Watch "Inner workings of AffineTransform" New topic
Author

Inner workings of AffineTransform

Caleb Kemper
Greenhorn

Joined: Feb 08, 2012
Posts: 27

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?

Thanks,
Caleb
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you're interested in performance, then the best approach is to try the two approaches you are considering, measure the performance, and choose the one which is more performant.

Examining code and expecting you can extrapolate from that to a conclusion about performance often doesn't work, especially when you're looking at inconsequential things like creating an object.
Caleb Kemper
Greenhorn

Joined: Feb 08, 2012
Posts: 27

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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
 
subject: Inner workings of AffineTransform
 
Similar Threads
How to Rotate with AffineTransform and keep the orignal coordinates ?
AffineTransform make an image move
What exactly is this graphics object?
How does this code work
Ajax: Back to square one