Pyevolve benchmark on different Python flavors

所以,我做了一个比较Pyevolve GP / GA核心的不同Python解释。I’ve used my Pentium Core 2 Duo (E4500 @ 2.20GHz, 1GB RAM), using Ubuntu 9.04 and Windows XP SP3 just for IronPython 2.6.1 (IronPython doesn’t run with Mono, so I used the win xp with .net 2.0).

使用的翻译是:

Unladen Swallow 2009Q2

我试着用2009Q3(当前主干线),但我认为这是不稳定的是,因为它比2009Q2更慢,所以我用2009Q2;我只使用默认的配置参数时(./configure)与GCC 4.3.3编译它。

CPython的2.6.2

I used the default CPython package of Ubuntu 9.04.

CPython的2.5.4

我使用的Ubuntu 9.04的默认CPython的包也一样,包装的python2.5。

PyPy 1.1.0(SVN:r68612)

我使用的存储库的最后一个SVN版本,释放68612.我的奔腾酷睿2只有1GB的RAM,和PyPy翻译过程中吃更多的内存比Java(遗憾的笑话),所以我用一个笔记本的3GBRAM创建pypy-C,有什么耗时1小时(我用-opt = 3)和一个美丽的ASCII曼德尔布罗分形

Jython的2.5.1

I used the default installer from the Jython project site. I used the Sun JRE 1.6.0_16.

IronPython 2.6.10920.0

我已经使用可在IronPython的项目现场与MS .NET 2.0的2.6 RC1。

为了测试我用这个源代码(一个简单的球体功能)的GA芯:

从进口pyevolve存取器pyevolve进口G1DList,从pyevolve进口GSimpleGA Initializators,Consts#这是球函数DEF球(的Xlist):总= 0对于i中的Xlist:总+ = I ** 2返回总DEF run_main():基因组= G1DList.G1DList(140)genome.setParams(rangemin = -5.12,的RangeMax = 5.13)genome.initializator.set(Initializators.G1DListInitializatorReal)genome.mutator.set(Mutators.G1DListMutatorRealGaussian)genome.evaluator.set(球体)GA= GSimpleGA.GSimpleGA(基因组,种子= 666)ga.setMinimax(Consts.minimaxType [ “最小化”])ga.setGenerations(1500)ga.setMutationRate(0.01)ga.evolve(freq_stats = 500)最好= ga.bestIndividual()如果__name__ == “__main__”:run_main()

And to test the GP core, I’ve used this source-code (a simple symbolic regression):

from pyevolve import GTree from pyevolve import Mutators from pyevolve import GSimpleGA, Consts, Util import math rmse_accum = Util.ErrorAccumulator() def gp_add(a, b): return a+b def gp_sub(a, b): return a-b def gp_mul(a, b): return a*b def gp_sqrt(a): return math.sqrt(abs(a)) def eval_func(chromosome): global rmse_accum rmse_accum.reset() code_comp = chromosome.getCompiledCode() for a in xrange(0, 10): for b in xrange(0, 10): evaluated = eval(code_comp) target = math.sqrt((a*a)+(b*b)) rmse_accum += (target, evaluated) return rmse_accum.getRMSE() def main_run(): genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator += eval_func genome.mutator.set(Mutators.GTreeGPMutatorSubtree) ga = GSimpleGA.GSimpleGA(genome, seed=666) ga.setParams(gp_terminals = ['a', 'b'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(40) ga.setCrossoverRate(1.0) ga.setMutationRate(0.08) ga.setPopulationSize(800) ga(freq_stats=10) best = ga.bestIndividual() if __name__ == "__main__": main_run()

更新19/08:the x-axis is measured in ““, and the y-axis is the python flavor;

结果列在下面的图表描述:

pyevolve_pyvms我们可以看到,空载燕子2009Q2确实与CPython 2.6.2好一点的表现,但Jython和PyPy(实验)被留在那种情况下,力挺IronPython的2.6.1。

Jinja2 in a Java JSP

这是一个简单的技巧可以使用Jython的;调用jinja2template engine under JSP we instantiate the蟒蛇InterpreterClass of Jython, set some parameters in the interpreter and then call jinja2 to render a template and write to the Java“走出去”object.

要安装的Jython,只需下载最新的稳定版本的Jython 2.5,然后将其安装为“单机版”;安装程序会创建一个简单的jython.jarfile under the installation directory, copy this package to your Java web project under the\ WEB-INF \ lib中or where you put your web application libraries.

后来,Jinja2的模块复制到\编译\班

创建下一个简单的模板WebContent\templates\template.html下面的内容:

This is just a Jinja2 template test ! Parameter "p" ={{ request.getParameter("p") }}获得会话属性:{{session.getAttribute( “SESSION_ATTRIBUTE”)}}Iterating over Java array:
    {%用于用户在用户%}
  • {{ user }}
  • {%ENDFOR%}

现在创建一个在的根名为index.jsp文件WebContent,与内容:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="org.python.util.PythonInterpreter" %>JSP下的Jinja2模板
<%PythonInterpreter PY =新PythonInterpreter();串[]用户= {“用户一号”,“用户二号”};session.setAttribute( “SESSION_ATTRIBUTE”, “测试会议”);py.set( “OUT”,出);py.set( “请求”,请求);py.set( “会话”,会议);py.set( “用户”,用户);py.set( “context_path”,application.getRealPath( “/”)+ “模板”);py.exec( “从进口的Jinja2环境FileSystemLoader”);py.exec( “ENV =环境(装载机= FileSystemLoader(context_path))”); py.exec("template = env.get_template('template.html')"); py.exec("out.write(template.render(locals()))"); %>

该结构是这样的:

structure

And the output will be something like this:

出

好消息:IronPython和Jython的兼容性!

Good news, I’ve tested Pyevolve 0.5 with theIronPython的2.0.1andJython的2.5b1和框架(与CPython的2.5和2.6进行比较时,除了性能的损失)的工作完美。不工作的唯一功能与统计转储sqlite3,正弦没有sqlite3在默认安装的Jython和IronPython的。要在IronPython的Pyevolve工作,您必须安装zlib的模块对于IronPython和导入Python模块是这样的:

进口SYS sys.path.append(R “C:\ python25 \ LIB”)

With this compatibility issue, you can use Pyevolve on your .NET platform or in your Java applications.