Source

Jython Experiments / experiments / util / compare.py

Full commit
#!/usr/bin/env python
import optparse
import os
import re
import subprocess
import sys

jython_head = ['/home/shashank/workspace/jython/dist/bin/jython',
               #'-J-XX:+UnlockExperimentalVMOptions', '-J-XX:+EnableInvokeDynamic',
               '-J-server', '-J-noverify']

jython_experimental = ['/home/shashank/workspace/jython-gradual/dist/bin/jython',
                      # '-J-XX:+UnlockExperimentalVMOptions', '-J-XX:+EnableInvokeDynamic',
                       '-J-server', '-J-noverify', '-S']

jython_experimental = ['/home/shashank/workspace/jython-experiments/dist/bin/jython',
                      # '-J-XX:+UnlockExperimentalVMOptions', '-J-XX:+EnableInvokeDynamic',
                       '-J-server', '-J-noverify', '-S']


JYTHON_JAVA_HOME = '/home/shashank/bin/jdk1.7.0_04'


def CallCommand(command, cwd=None, env=None):
    print ' '.join(command)
    subproc = subprocess.Popen(command,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               cwd=cwd, env=env)
    stdout, stderr = subproc.communicate()
#    print stdout
#    print stderr
    return stdout, stderr

def ProcessOutput((stdout, stderr)):
    time_t = re.findall(r"taken: ([\d\.]+)", stdout)[0]
    return float(time_t)

def main():
    all_exes = [
        #'/home/shashank/workspace/jython-experiments/experiments/minmax/min_max.py',
        '/home/shashank/workspace/jython-experiments/experiments/ForLoop/huge_for_loop.py',
        #'/home/shashank/workspace/jython-experiments/experiments/matrix/matrix_mul.py',
        #'/home/shashank/workspace/jython-experiments/experiments/nested/nested_loops.py',
        #'/home/shashank/workspace/jython-experiments/experiments/fib/fib.py',
        #'/home/shashank/workspace/jython-gradual/tmp/global-rec.py'
        ]

    frameless = '/home/shashank/workspace/jython-experiments/experiments/fib/fib.py'
    f = open("/home/shashank/result-global-call.csv", 'w')
    f.write("count, global-cc, trunk\n")
    speedups = []
    for exe in all_exes:
        for n in xrange(10):
            head = 0.0
            expr = 0.0
            head_times = []
            exper_times = []
            print 'Head  Experimental  Speedup'
            for i in xrange(10):
                head_times.append(ProcessOutput(CallCommand(jython_head + [exe])))
                exper_times.append(ProcessOutput(CallCommand(jython_experimental + [exe])))
                #            print 'Head:', head_times, 'exper:', exper_times
                #                 'Head  Experimental  Speedup'
                print '  .          .      ', head_times[i] / exper_times[i]

        print '======== Total speedup for ', exe
	for tmp_h in head_times:
	    head += tmp_h
	for tmp_e in exper_times:
	    expr += tmp_e

        print 'Jython Head:', head/10
        print 'Jython Experimental:', expr/10
        speed = str(head / expr)
        speedups.append(speed)
        print 'Speedup:', speed

    print '\n\nAll the speedups:\n', '\n'.join(speedups)


if __name__ == '__main__':
    main()