From: Utkarsh U. <mus...@gm...> - 2007-04-15 15:57:58
|
Hi there, > 1. Surely it is answered already, but I don't find such an answer. I want to > know which is more efficient, coding to python or java? I mean for operations > that are present in jython through both python and jython. For simplicity: > What is more efficient and what is the usual to follow, what is the jythonic way? Well, this indeed is an oft asked question, asked so so often that there are separate tools for the process called 'profilers'. You can look them up on Google, or even the Python Manual. BTW, to answer your question, I used the module 'profile' and got the following results: > > In [0]: import math > In [1]: math.pow(2,2) > Out [1]: 4.0 >>> 2 function calls in 0.250 CPU seconds > In [2]: from java.lang import Math > In [3]: Math.pow(2,2) > Out [3]: 4.0 > >>> 2 function calls in 0.015 CPU seconds In the hind sight, the results seem somewhat obvious (though I never imagined such an order of magnitude of difference). The jython code is after all converted to a Java analogue and then run (NOT TO BE TAKEN LITERALLY, there is a LOT behind the process). So a direct Java implementation ought to make it somewhat straight forward for Jython, resulting in a faster code. > > 2. If I want to implement a keyword-like function like print or import how do I > do it? I want to have something like that : foo bar , and execute foo with param > bar. A function that doesn't require parenthesis. Could someone tell me where I > can find such implementation in the jython source code? > This may not be all that wise, neither fruitful, an idea. It can be done with considerable hacking of the course code, but then there must exist a Pythonic way of doing the same thing. --musically_ut -- Never trust a spiritual leader who cannot dance. ~Mr. Miyagi, The Next Karate Kid |