Quantcast

slow overloaded method

classic Classic list List threaded Threaded
5 messages Options
wa
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

slow overloaded method

wa
Hello,

Jython newbie here, so I apologize if this is a silly question. I am seeing some  strange behavior I don't understand when I call an overloaded Java method from a Jython script.

Here is my Java class:
public class TestClass {
  public static float[][][] overloaded(float[][][] x) {
    return x;
  }
  public static float[][][][] overloaded(float[][][][] x) {
    return x;
  }
  public static float[][][] zeros(int n1, int n2, int n3) {
    return new float[n3][n2][n1];
  }
}
and here is my Jython script:
import time,TestClass
n1,n2,n3 = 250,250,250
z = TestClass.zeros(n1,n2,n3)
start = time.time()
TestClass.overloaded([z,z,z])
print 'time =',(time.time()-start)
This Jython script takes about 1 minute to run (I'm on a Mac, if that matters), but if I comment out the first method in TestClass.java the script takes almost no time at all. I'm confused why it takes so much longer when the method is overloaded. Am I missing something here?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: slow overloaded method

Johannes Buchner
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi wa,

On 02/25/12 02:21, wa wrote:

> Here is my Java class:
>
> public class TestClass { public static float[][][]
> overloaded(float[][][] x) { return x; } public static float[][][][]
> overloaded(float[][][][] x) { return x; } public static float[][][]
> zeros(int n1, int n2, int n3) { return new float[n3][n2][n1]; } }
>
> and here is my Jython script:
>
> import time,TestClass n1,n2,n3 = 250,250,250 z =
> TestClass.zeros(n1,n2,n3) start = time.time()
> TestClass.overloaded([z,z,z])

You are handing over a list that contains 3 float[][][] arrays. Don't
you want to do just
TestClass.overloaded(z)
I presume that Jython goes through the array and tries to do some sort
of conversion to bash it into a usable form for the Java call.
Please clarify what you expect the code to do.

> print 'time =',(time.time()-start)
>
> This Jython script takes about 1 minute to run (I'm on a Mac, if
> that matters), but if I comment out the first method in
> TestClass.java the script takes almost no time at all. I'm confused
> why it takes so much longer when the method is overloaded. Am I
> missing something here?

Cheers,
Johannes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)

iEYEARECAAYFAk9IjEoACgkQ7X1+MfqVcr2lMQCePJaUTbyBi6tNK69h53HoTaVU
9lcAoIO5gauxCCafxvVvsG3RcBNuQI/q
=2zDs
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: slow overloaded method

Jeff Emanuel
In reply to this post by wa

I ran your test on Windows, and it is still slow, so it is not a Mac problem.
I don't know the reason it is so slow, but I noticed that in old versions of Jython (2.1 and 2.2),
your script takes about 5 seconds instead of 60.

If you change your script to create a 4D array explicitly, then it runs much faster.
This ran in about 1ms for me, which is the same time as without the overloaded 3D array
method.

import time,TestClass
n1,n2,n3 = 250,250,250
z = TestClass.zeros(n1,n2,n3)

import java,jarray
z4d = jarray.array([z,z,z],java.lang.Class.forName('[[[F'))

start = time.time()
TestClass.overloaded(z4d)
print 'time =',(time.time()-start)



On 2/24/2012 6:21 PM, wa wrote:

> Hello,
>
> Jython newbie here, so I apologize if this is a silly question. I am seeing
> some  strange behavior I don't understand when I call an overloaded Java
> method from a Jython script.
>
> Here is my Java class:
>
> and here is my Jython script:
>
> This Jython script takes about 1 minute to run (I'm on a Mac, if that
> matters), but if I comment out the first method in TestClass.java the script
> takes almost no time at all. I'm confused why it takes so much longer when
> the method is overloaded. Am I missing something here?
>
> --
> View this message in context: http://python.6.n6.nabble.com/slow-overloaded-method-tp4504592p4504592.html
> Sent from the jython-users mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Virtualization&  Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Jython-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: slow overloaded method

Pierre Thibault-3
In reply to this post by wa
Hello wa,

Well, the array is big. 250x250x250 means 15625000 elements.

And you cannot do:
TestClass.overloaded([z,z,z])

Because Jython represents arrays like this:

array('f', [0.0])

This was the output of
: TestClass.zeros(1,2,3)[0][0]
Hope it helps.

2012/2/24 wa <[hidden email]>
Hello,

Jython newbie here, so I apologize if this is a silly question. I am seeing
some  strange behavior I don't understand when I call an overloaded Java
method from a Jython script.

Here is my Java class:

and here is my Jython script:

This Jython script takes about 1 minute to run (I'm on a Mac, if that
matters), but if I comment out the first method in TestClass.java the script
takes almost no time at all. I'm confused why it takes so much longer when
the method is overloaded. Am I missing something here?

--
Pierre Thibault

Python Developer/Développeur Python
Montréal, QC





------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
wa
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: slow overloaded method

wa
In reply to this post by Johannes Buchner
Johannes Buchner wrote
You are handing over a list that contains 3 float[][][] arrays. Don't
you want to do justTestClass.overloaded(z)
I presume that Jython goes through the array and tries to do some sort
of conversion to bash it into a usable form for the Java call.
Please clarify what you expect the code to do.
I want to call TestClass.overloaded(float[][][][] x), which is why I pass a list of float[][][] arrays.
Jeff Emanuel wrote
If you change your script to create a 4D array explicitly, then it runs much faster.
This ran in about 1ms for me, which is the same time as without the overloaded 3D array
method.
This what I ended up doing.  I guess Jython is doing some conversion as Johannes suggested, but I still don't understand why this conversion takes so long only when the method is overloaded.
Loading...