#=============================================================================
# Copyright Texas Instruments 2003. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from java.lang import System
t = 0
max = 1000000
itr = 3
global global_cnt
global_cnt = 0
i = 0
while i < itr:
print '
| Results for Jython: bench.py |
'
print ' | Test | Time (ms) |
'
total = 0
# simple loop:
t = System.currentTimeMillis()
cnt = 0
j = 0
while j < max:
cnt = cnt + 1
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | simple loop: | %d |
' % t
# simple fxn:
def count():
global global_cnt
global_cnt = global_cnt + 1
t = System.currentTimeMillis()
j = 0
while j < max:
count()
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | simple fxn: | %d |
' % t
# function call with argument:
def count(a):
global global_cnt
global_cnt = global_cnt + 1
t = System.currentTimeMillis()
j = 0
while j < max:
count(j)
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | simple fxn with arg: | %d |
' % t
# simple fxn with local:
def count():
foo = 1
global global_cnt
global_cnt = global_cnt + 1
t = System.currentTimeMillis()
j = 0
while j < max:
count()
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | simple fxn with local: | %d |
' % t
# member dereference:
class Foo:
def __init__(self):
self.cnt = 0
def count(self):
self.cnt = self.cnt + 1
obj = Foo()
t = System.currentTimeMillis()
j = 0
while j < max:
obj.cnt = obj.cnt + 1
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | member dereference: | %d |
' % t
# string concationation test:
str = ""
t = System.currentTimeMillis()
j = 0
while j < 3000:
str = str + "0123456789"
j = j + 1
t = System.currentTimeMillis() - t
total = total + t
print ' | string concat: | %d |
' % t
print ' | total: | %d |
' % total
i = i + 1