[285] in java-interest
Java vs Python
daemon@ATHENA.MIT.EDU (George Reynolds)
Mon Jun 12 16:51:21 1995
Date: Mon, 12 Jun 1995 16:34:43 -0400
From: George Reynolds <george@dvcorp.com>
To: java-interest@java.Eng.Sun.COM
Cc: george@dvcorp.com
Hello,
I just started looking at Java and am interested in comparing
Java to Python. The main areas of comparison are performance,
language features and extensibility
Performance
-----------
I noticed the numbers on page 48 of the white paper on
times for object creation and thought I would compare with
Python. Included is a simple module and a test script. The test
exercises method calls (get and set) and object creation.
In every case python comes in at 200000/sec. Would someone
setup the same script in Java so we could do a reasonable
comparison?
Language Features:
------------------
Python is a high level language in that it supports composable
set of objects like tuples, dictionaries, arrays etc and provides
syntactic support for their usage. For example one can return
a tuple from a method by saying
def foo(self):
return (a,b)
and then use the functions as
x,y = o.foo()
Similarly dictionaries are supported as in
dict = {'arr':[], 'x':10, 'd':{}}
Here dict is a dictionary which has an array at key 'arr',
an integer at key 'x' and another dictionary at at key 'd'
dict['d']['bar'] = 5
adds an entry to the 'd' dictionary.
There is no mention of these kinds of features in the white
paper. Are they planned for the language? If not it looks like
Java is a cleaned up C++ but still a low level language. IMHO
its exactly these features that makes python so powerful.
Extensibility
-------------
Python is VERY easy to extend with C or C++ code. How extensible
is Java? For example Tk of tcl/Tk fame has been bound into Python
(and not by the person who deveoped the language). What would be
involved in doing this with Java?
George
george@dvcorp.com
------------------------------------snip--------------------------------
#
# Module pt for simple performance test
#
NUM_ITERS = 1000
class point:
def __init__(self, x, y):
self.x = x
self.y = y
def getX(self):
return self.x
def getY(self):
return self.y
def setX(self, x):
self.x = x
def setY(self, y):
self.y = y
def getXVal():
pnt = point(1,2)
for i in range(NUM_ITERS):
pnt.getX()
def setXVal():
pnt = point(1,2)
for i in range(NUM_ITERS):
pnt.setX(3)
def createPt():
for i in range(NUM_ITERS):
pnt = point(1,2)
#-------------------------------snip----------------------------------
#
# Test program for pt.py
#
import profile, pt
profile.run("pt.getXVal()")
print
profile.run("pt.setXVal()")
print
profile.run("pt.createPt()")
#-------------------------------snip----------------------------------
Results
-------
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.017 0.017 7.700 7.700 <string>:0(?)
1 2.833 2.833 7.683 7.683 prof.py:6(getXVal)
1000 4.850 0.005 4.850 0.005 pt.py:10(getX)
1 0.000 0.000 0.000 0.000 pt.py:6(__init__)
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.017 0.017 7.800 7.800 <string>:0(?)
1 2.717 2.717 7.783 7.783 prof.py:12(setXVal)
1000 5.067 0.005 5.067 0.005 pt.py:16(setX)
1 0.000 0.000 0.000 0.000 pt.py:6(__init__)
ncalls tottime percall cumtime percall filename:lineno(function)
1 2.967 2.967 7.933 7.933 prof.py:18(createPt)
1 0.000 0.000 7.933 7.933 <string>:0(?)
1000 4.967 0.005 4.967 0.005 pt.py:6(__init__)
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com