Nidelven IT - All about Python, Zope & Plone - and Open Source!

Here you'll find issues related to our services. Mostly about Python, Zope and Plone, as well as hosting-related issues.

"Keeping IT real"






Older entries



Atom - Subscribe - Categories
Previous | Next

Python in Java

So, these last couple of days I've been playing around with Jep ( http://jepp.sourceforge.net ), the project that embeds Python and makes it available in Java.. it's been a while since I've worked with Java, dependencies and so on, so been pulling hair a bit to get things working.

But, got it working, and one things I've become more aware of lately is how things run, in terms of speed. So I decided to compare Jep, Jython ( http://www.jython.org ) and (C)Python ( http://www.python.org ).

Here's Jep:

>>> from test import pystone
>>> for x in range(10):
... pystone.main()
...
Pystone(1.1) time for 50000 passes = 1
This machine benchmarks at 50000 pystones/second
Pystone(1.1) time for 50000 passes = 1.01
This machine benchmarks at 49505 pystones/second
Pystone(1.1) time for 50000 passes = 1.01
This machine benchmarks at 49505 pystones/second
Pystone(1.1) time for 50000 passes = 1.01
This machine benchmarks at 49505 pystones/second
Pystone(1.1) time for 50000 passes = 1
This machine benchmarks at 50000 pystones/second
Pystone(1.1) time for 50000 passes = 0.99
This machine benchmarks at 50505.1 pystones/second
Pystone(1.1) time for 50000 passes = 1.01
This machine benchmarks at 49505 pystones/second
Pystone(1.1) time for 50000 passes = 1
This machine benchmarks at 50000 pystones/second
Pystone(1.1) time for 50000 passes = 0.99
This machine benchmarks at 50505.1 pystones/second
Pystone(1.1) time for 50000 passes = 1.01
This machine benchmarks at 49505 pystones/second
>>>

It is fairly consistent when it comes to the number of pystones.

Then trying Jython:

>>> for x in range(10):
... pystone.main()
...
Pystone(1.1) time for 50000 passes = 1.816
This machine benchmarks at 27533 pystones/second
Pystone(1.1) time for 50000 passes = 1.128
This machine benchmarks at 44326.2 pystones/second
Pystone(1.1) time for 50000 passes = 0.569
This machine benchmarks at 87873.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.495
This machine benchmarks at 101010 pystones/second
Pystone(1.1) time for 50000 passes = 0.574
This machine benchmarks at 87108 pystones/second
Pystone(1.1) time for 50000 passes = 0.519
This machine benchmarks at 96339.1 pystones/second
Pystone(1.1) time for 50000 passes = 0.497
This machine benchmarks at 100604 pystones/second
Pystone(1.1) time for 50000 passes = 0.501
This machine benchmarks at 99800.4 pystones/second
Pystone(1.1) time for 50000 passes = 0.575
This machine benchmarks at 86956.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.515
This machine benchmarks at 97087.3 pystones/second
>>>

Which shows a great variation, but improvement, in how many pystones can be calculated per second. I assume this is due to the Java HotSpot technology. How well the HotSpot system works with real-life code and data is a different matter.

Finally, we have (C)Python:

>>> for x in range(10):
... pystone.main()
...
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.85
This machine benchmarks at 58823.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.87
This machine benchmarks at 57471.3 pystones/second
Pystone(1.1) time for 50000 passes = 0.87
This machine benchmarks at 57471.3 pystones/second
Pystone(1.1) time for 50000 passes = 0.85
This machine benchmarks at 58823.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
Pystone(1.1) time for 50000 passes = 0.86
This machine benchmarks at 58139.5 pystones/second
>>>

Which shows a fairly consistent number of pystones, around 58000 per second.

Now, the reason I started looking at Jython and then Jep, is that I'm looking at some Java-based content and development frameworks. I'm not sure if there is a big difference in how you can use Jep and Jython, but these are alternatives that can be used when developing in Java systems. In most cases data needs to be sent back to the Java-based application.

Being able to script things fast in Python is a benefit in some situations for rapid prototyping and so on. As is my experience with Python, the speed in Python can be good enough with the right programming techniques and systems. If the applications run too slowly, then switching between Jep and Jython can be a good idea to see which one actually runs the fastest.

[Permalink] [By morphex] [Python-only or > 0.5 Python related (Atom feed)] [2013 15 May 18:07 GMT+2]

Add comment (text format)

Passphrase

A passphrase is required to comment on this weblog. It is required to make sure that bots aren't doing automatic spamming. It is: nit is the best!.

Title

Name

Email

Comment