From: <th...@us...> - 2009-08-23 22:46:59
|
Revision: 6714 http://jython.svn.sourceforge.net/jython/?rev=6714&view=rev Author: thobes Date: 2009-08-23 22:46:49 +0000 (Sun, 23 Aug 2009) Log Message: ----------- Added a bootstrap script that sets up Jython with basic libraries. Also added the beginnings of a benchmarking library with more flexibility than timeit. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/build.xml trunk/sandbox/tobias/tests/parrotbench/b.py Added Paths: ----------- trunk/sandbox/tobias/bootstrap trunk/sandbox/tobias/lib/ trunk/sandbox/tobias/lib/benchmark.py trunk/sandbox/tobias/lib/benchmark.sh Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/.classpath 2009-08-23 22:46:49 UTC (rev 6714) @@ -20,7 +20,6 @@ <classpathentry kind="lib" path="jython/extlibs/constantine-0.4.jar"/> <classpathentry kind="lib" path="jython/extlibs/cpptasks/cpptasks.jar"/> <classpathentry kind="lib" path="jython/extlibs/jarjar-0.7.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jline-0.9.94.jar"/> <classpathentry kind="lib" path="jython/extlibs/jna-posix.jar"/> <classpathentry kind="lib" path="jython/extlibs/jna.jar"/> <classpathentry kind="lib" path="jython/extlibs/junit-3.8.2.jar"/> @@ -41,7 +40,9 @@ <classpathentry kind="lib" path="jython/Lib/test/syspath_import.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (Mac OS X default)"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> - <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.2.jar"/> - <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.2.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.3.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.3.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jline-0.9.95-SNAPSHOT.jar"/> + <classpathentry kind="lib" path="jython/extlibs/livetribe-jsr223-2.0.5.jar"/> <classpathentry kind="output" path="target/build"/> </classpath> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-08-23 22:46:49 UTC (rev 6714) @@ -1,4 +1,5 @@ -<?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="brand-version,antlr_gen,"/> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> @@ -18,7 +19,7 @@ <mapEntry key="eclipse.running" value="true"/> <mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> <mapEntry key="eclipse.home" value="/Library/eclipse"/> -<mapEntry key="compile.dir" value="${project_loc}/target/build"/> +<mapEntry key="compile.dir" value="${project_loc:/target/build}"/> <mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> </mapAttribute> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/build.xml}"/> Added: trunk/sandbox/tobias/bootstrap =================================================================== --- trunk/sandbox/tobias/bootstrap (rev 0) +++ trunk/sandbox/tobias/bootstrap 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1,267 @@ +#!/bin/sh + +# <configuration> +# <command names> +CMD_JYTHON=jython +CMD_INSTALL=easy_jython_install +CMD_VIRTUAL=virtualjython +CMD_BENCH=benchmark_jython +# </command names> +# <config files> +CLASSPATH_FILE=~/.jython.classpath +JYTHONPATH_FILE=~/.jython.path +JYTHONOPTIONS_FILE=~/.jython.options +JAVAHOME_FILE=~/.jython.java_home +# </config files> +DEFAULT_INSTALL_PATH=~/bin +BIN_OFFSET=target/dist/bin +EZ_SETUP=http://peak.telecommunity.com/dist/ez_setup.py +BUILD_TARGET= +TEMP_DIR=/tmp +# </configuration> + +install() +{ + if [ -n "$1" ]; then + INSTALL_PATH=$1 + else + echo -n "Enter installation path [$DEFAULT_INSTALL_PATH]: " + read INSTALL_PATH + if [ -z "$INSTALL_PATH" ]; then + INSTALL_PATH=$DEFAULT_INSTALL_PATH + fi + fi + if [ "`dirname ${INSTALL_PATH}x`" != "`dirname $INSTALL_PATH`" ]; then + INSTALL_PATH=`dirname ${INSTALL_PATH}x` + fi + if [ ! -e "$BASE/lib/benchmark.sh" ]; then + CMD_BENCH= + fi + TARGET=$BASE/`basename $EXE` + for SCRIPT in {$CMD_JYTHON,$CMD_INSTALL,$CMD_VIRTUAL,$CMD_BENCH}; do + if ln -is $TARGET $INSTALL_PATH/$SCRIPT; then + echo installed $INSTALL_PATH/$SCRIPT + fi + done +} + +build() +{ + CUR_DIR=`pwd` + cd $BASE + if [ -z "`which ant`" ]; then + echo ERROR: cannot build Jython, could not find ant + exit 1 + fi + echo Rebuilding Jython + ant clean + if [ -n "`which svn`" ]; then + echo Updating working copy + svn up + fi + echo Building Jython + ant $BUILD_TARGET + cd $CUR_DIR +} + +jython() +{ + JYTHON_COMMAND=$BIN_DIR/jython + if [ ! -e "$JYTHON_COMMAND" ]; then + build + elif [ 0 -eq 0 ]; then + # disable the next branch - it is too slow... + echo -n + elif [ -n "`which svn`" ]; then + # TODO: speed up this comparison - then it can be enabled... + BASE_REVISION=`svn info | grep ^Revision` + if [ $? -ne 0 ]; then + echo ERROR: broken working copy + exit 1 + fi + HEAD_REVISION=`svn info -r HEAD | grep ^Revision` + if [ $? -eq 0 ]; then + if [ "$BASE_REVISION" != "$HEAD_REVISION" ]; then + build + fi + fi + fi + if [ -e "$JYTHONOPTIONS_FILE" ]; then + JYTHON_OPTIONS=`lam -s -J $JYTHONOPTIONS_FILE | paste -s -d \ -` + fi + while [ "${1:0:2}" == '-J' ]; do + case "${1:2}" in + # Classpath parameters have arguments + -cp) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1 $2" + shift + ;; + -classpath) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1 $2" + shift + ;; + *) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1" + ;; + esac + shift + done + if [ "$1" == "-m" -a "$2" == "benchmark" ]; then + # benchmarking special case add timing to jython + if [ -e "$BASE/lib/benchmark.sh" ]; then + source $BASE/lib/benchmark.sh + fi + fi + $JYTHON_COMMAND $JYTHON_OPTIONS "$@" + if [ "$1" == "--help" ]; then + echo Bootstrap launcher configuration files: + echo $CLASSPATH_FILE - Configure CLASSPATH, one path per line + echo $JYTHONPATH_FILE - Configure JYTHONPATH, one path per line + echo $JYTHONOPTIONS_FILE - Options passed to the JVM, one per line + fi +} + +benchmark_jython() +{ + for VM in {client,server}; do + echo "=== Benchmarking Jython ($VM VM) ===" + if [ -n "$JAVA_HOME" ]; then + echo " * JAVA_HOME = $JAVA_HOME" + fi + jython -J-$VM -m benchmark "$@" + done +} + +benchmark() +{ + while [ $# -gt 0 ] ; do + case "$1" in + --help) + echo "Run benchmarking of a Python module in CPython and Jython" + echo + echo "Usage:" + echo " $0 <options> <script>.py" + echo "Where <options> can be one or several of the following:" + echo " --jython Run the benchmark in Jython only" + echo " --help Print this message and exit" + exit 0 + ;; + --jython) + JYTHON_ONLY="true" + ;; + *) + break + ;; + esac + shift + done + if [ -z "$1" ]; then + echo "ERROR: No script supplied" + echo "See '$0 --help' for options" + exit 1 + fi + if [ -z "$JYTHON_ONLY" ]; then + echo "=== Benchmarking CPython ===" + time python $BASE/lib/benchmark.py --scripted "$@" + fi + if [ -e "$JAVAHOME_FILE" ]; then + for JAVA_HOME in `cat $JAVAHOME_FILE`; do + export JAVA_HOME + benchmark_jython --scripted "$@" + done + else + benchmark_jython --scripted "$@" + fi +} + +easy_install() +{ + if [ ! -e "$BIN_DIR/easy_install" ]; then + if [ -n "`which wget`" ]; then + wget --output-document=$TEMP_DIR/ez_setup.py $EZ_SETUP + elif [ -n "`which curl`" ]; then + curl -o $TEMP_DIR/ez_setup.py $EZ_SETUP + else + echo ERROR: could not install setuptools + exit 1 + fi + jython $TEMP_DIR/ez_setup.py + rm $TEMP_DIR/ez_setup.py + fi + $BIN_DIR/easy_install "$@" +} + +virtualenv() +{ + if [ ! -e "$BIN_DIR/virtualenv" ]; then + easy_install virtualenv + fi + $BIN_DIR/virtualenv "$@" +} + +NAME=`basename $0` +EXE=$0 +while [ -L "$EXE" ]; do + EXE=`readlink $EXE` +done +BASE=`dirname $EXE` +BASE=`cd $BASE; pwd` +BIN_DIR=$BASE/$BIN_OFFSET + +if [ "$EXE" == "$0" ]; then + install "$@" +else + # Setup CLASSPATH + if [ -e "$CLASSPATH_FILE" ]; then + LOCAL_CLASSPATH=`paste -s -d : $CLASSPATH_FILE` + fi + if [ -n "$CLASSPATH" ]; then + if [ -n "$LOCAL_CLASSPATH" ]; then + export CLASSPATH=$LOCAL_CLASSPATH:$CLASSPATH + fi + else + export CLASSPATH=$LOCAL_CLASSPATH + fi + # Setup JYTHONPATH + if [ -e "$JYTHONPATH_FILE" ]; then + LOCAL_JYTHONPATH=`paste -s -d : $JYTHONPATH_FILE` + fi + if [ -n $"JYTHONPATH" ]; then + if [ -n "$LOCAL_JYTHONPATH" ]; then + export JYTHONPATH=$LOCAL_JYTHONPATH:$BASE/lib:$JYTHONPATH + else + export JYTHONPATH=$BASE/lib:$JYTHONPATH + fi + else + if [ -n "$LOCAL_JYTHONPATH" ]; then + export JYTHONPATH=$LOCAL_JYTHONPATH:$BASE/lib + else + export JYTHONPATH=$BASE/lib + fi + fi + # Setup JAVA_HOME + if [ -z "$JAVA_HOME" ]; then + if [ -e "$JAVAHOME_FILE" ]; then + export JAVA_HOME=`head -n 1 $JAVAHOME_FILE` + fi + fi + # Dispatch command + case "$NAME" in + $CMD_JYTHON) + jython "$@" + ;; + $CMD_INSTALL) + easy_install "$@" + ;; + $CMD_VIRTUAL) + virtualenv "$@" + ;; + $CMD_BENCH) + benchmark "$@" + ;; + *) + echo ERROR: unknown command \"$NAME\" + exit 1 + ;; + esac +fi Property changes on: trunk/sandbox/tobias/bootstrap ___________________________________________________________________ Added: svn:executable + * Modified: trunk/sandbox/tobias/build.xml =================================================================== --- trunk/sandbox/tobias/build.xml 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/build.xml 2009-08-23 22:46:49 UTC (rev 6714) @@ -53,6 +53,9 @@ </exec> </target> + <target name="source dist"> + </target> + <target name="setup target"> <mkdir dir="${target.dir}"/> </target> Property changes on: trunk/sandbox/tobias/lib ___________________________________________________________________ Added: svn:ignore + *.class *.pyc Added: trunk/sandbox/tobias/lib/benchmark.py =================================================================== --- trunk/sandbox/tobias/lib/benchmark.py (rev 0) +++ trunk/sandbox/tobias/lib/benchmark.py 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Python benchmarking module + +Command line usage: + %(prog)s <module> [<module> ...] +""" + +from __future__ import with_statement + +import sys, traceback + +if __name__ == '__main__': + from benchmark import __main__ + try: + __main__(*sys.argv) + except: + traceback.print_exc() + sys.exit(1) + else: + sys.exit(0) + +__all__ = ('benchmark', 'run') + +def benchmark(*args, **params): + if len(args) > 1: + raise ValueError("Illegal use of benchmark decorator.") + def decorator(func): + func.__benchmark__ = params + return func + if args: + return decorator(*args) + else: + return decorator + +def run(*cases, **params): + if not cases: + if hasattr(sys, '_getframe'): + frame = sys._getframe(1) + while frame and frame.f_globals['__name__'] == __name__: + frame = frame.f_back + if frame: + cases = (frame.f_globals['__name__'],) + benchmarks = [] + for case in cases: + if isstring(case): + if case.endswith('.py'): + env = {'__name__':'__benchmark__', '__file__':case} + try: + with open(case) as file: + exec(file.read(), env) + except: + print("Error in benchmark file '%s'." % (case,)) + traceback.print_exc() + continue + else: + module = _Dummy() + module.__benchmarks__ = env.get('__benchmarks__', ()) + elif case in sys.modules: + module = sys.modules[case] + else: + env = {} + try: + exec("import %s as module" % (case,), env) + except: + print("No such benchmark module '%s'." % (case,)) + continue + else: + module = env['module'] + name = case + for case in getattr(module, '__benchmarks__', ()): + if isstring(case): + try: + benchmarks.append(getattr(module, case)) + except: + print("No such benchmark case '%s' in module '%s'." % + (case, name)) + else: + benchmarks.append((name, case)) + else: + benchmarks.append((None, case)) + _run(benchmarks, params) + +benchmark.run = run + +try: + basestring +except: + def isstring(string): + return isinstance(string, str) +else: + def isstring(string): + return isinstance(string, basestring) + +__DEFAULT__ = object() +class _Dummy(object): pass + +def _run(cases, params): + warmup = params.get('warmup', __DEFAULT__) + if warmup is __DEFAULT__: + pass + elif warmup is None: + pass + else: + pass + for module, case in cases: + name = ('%s.%s' % (module, case.__name__)) if module else case.__name__ + print name + +if sys.platform.lower().startswith('java'): + def _warmup(params): + warmup = params.pop('warmup', None) + if warmup is INTERACTIVE_WARMUP: + pass + elif warmup is not None: + return dict( + iterations=int(warmup), + ) +else: + def _warmup(params): + params.pop('warmup',None) + + +def __main__(script, *args): + from optparse import OptionParser + parser = OptionParser() + parser.add_option('--verbose', action='store_true', default=False) + parser.add_option('--scripted', action='store_true', default=False) + parser.add_option('--runs', type='int', default=1) + parser.add_option('--loops', type='int', default=10) + parser.add_option('--warmup-runs', type='int', default=1) + parser.add_option('--warmup-loops', type='int', default=1) + parser.add_option('--repetitions', '--reps', type='int', default=None) + options, args = parser.parse_args(list(args)) + + params = {'verbose': options.verbose + } + if options.repetitions is not None: + params['repetitions'] = options.repetitions + if not args: + print(__doc__ % {'prog': script}) + else: + run(*args,**params) Added: trunk/sandbox/tobias/lib/benchmark.sh =================================================================== --- trunk/sandbox/tobias/lib/benchmark.sh (rev 0) +++ trunk/sandbox/tobias/lib/benchmark.sh 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1 @@ +JYTHON_COMMAND="time $JYTHON_COMMAND" Modified: trunk/sandbox/tobias/tests/parrotbench/b.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b.py 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/tests/parrotbench/b.py 2009-08-23 22:46:49 UTC (rev 6714) @@ -9,7 +9,8 @@ import sys from time import time -WARMUP = 0 +WARMUP = 250 +#WARMUP = 0 TIMES = 3 NUMBER = 1 ITERATIONS = 1 @@ -38,7 +39,7 @@ print >>sys.stderr, "--> iteration", i for module in (b0, b2, b3, b4, b5, b6): # b1 ommitted mt = min(run(module, i)) - print >>sys.stderr, "best of 3:", mt + print >>sys.stderr, "best of %s:" % TIMES, mt t = time() - t print >>sys.stderr, "--> All done.", t This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |