[Proj] pj_transform performance issue

Frank Warmerdam warmerdam at pobox.com
Mon Nov 12 07:31:41 PST 2007


Herve Baille wrote:
> Hi
> 
> We are new in development using proj4.
> We used to develop our own C libraries and would like to use Proj4, but 
> we experienced a strange performance problem.
> 
> We initialize the projections with:
> pj_in = pj_init_plus("+init=epsg:4019");
> pj_out = pj_init_plus("+init=epsg:27572");
> 
> Then we loop 100000 times on the function call:
> for (i=0 ; i<nbloop ; i++) {
> pj_transform(pj_in, pj_out, 1, 0, &x, &y, 0);
> }
> We get the (correct) result in about 6 seconds.
> 
> Now we just integrate this call into a function
> int trans(projPJ pj_in, projPJ pj_out, double x, double y)
> {
> pj_transform(pj_in, pj_out, 1, 0, &x, &y, 0);
> return(0);
> }
> and call this function in the loop,
> for (i=0 ; i<nbloop ; i++) {
> trans(pj_in, pj_out, x, y);
> }
> then we get the (still correct) result in 30 seconds!
> 
> Now, if I pass the coordiantes of my intermediate function, by address 
> instead of by values,
> int trans(projPJ pj_in, projPJ pj_out, double *x, double *y)
> {
> pj_transform(pj_in, pj_out, 1, 0, x, y, 0);
> return(0);
> }
> We get the result in 6 seconds again.
> 
> What could be the reason for such a performance ratio?

Herve,

I'm quite surprised, and I don't know why you would see such a performance
problem.  But I will say that if trans() takes the x,y values by value
(as shown), then the calling variables will not be changed.  If you want
the values actually altered outside trans() they need to be passed by
reference.

> What are the rules to optimize pj_transform function?

I will note that it is highly desirable to pass many points to
pj_transform() at once.  Transforming points with one per call
is relatively expensive.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the Proj mailing list