预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10
亲,该文档总共13页,到这已经超出免费预览范围,如果喜欢就直接下载吧~
如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
python中嵌入。语言脚本python中嵌入。语言脚本借助Cinpy和C语言解释器TinyCC,可以在python程序里面直接嵌入。语言片断、不经编译直接使用C编写的函数了。win2k平台上,简单的测试对比数据如下(递归方法计算第四十项兔子数列fib(40))语言实现时间(单位:秒)评python官方纯pythonfib函数568.718天啊使用psyco加速的pythonfib函数17.922比较接近,还行使用swig直接转换的C语言编写的模块13.453使用Cinpy嵌入fib函数11.532VC6速度优化编译的可执行文件5.562编译的可执行文件6.719解释执行6.813FreeBASICfbc0.16b编译的可执行文件(-arch486)&022编译的可执行文件(-arch686)7.619forth4th35a24thexfib.4th277这个表现太失望了4thcsvfib.4thfib.hx4thlxfib.hx1964thIgfib.hxfib.cGforth-fastfib>gfth14.719不错,不过不是说和C的速度可以比嘛?怎么也就是优化的python的速度啊注,其余源程序freebasicfunctionfib(xasinteger)asintegerifx<=lthenreturn1elsereturnfib(x-l)+fib(x-2)endifendfunctiondimstarttime,endtimeasdoubledimresasintegerstarttime=timerres=fib(40)endtime=timerprintnfib(40)=;resprint"timeelapsed:(endtime-starttime)n4th:fib(x--y)dup2>ifdup1-recurseswap2-recurse+exitthendrop1;time41fib.crtimeswap-."timeelapsed".."s"crgforth-0.6.2:fib(x--y)dup2>ifdup1-recurseswap2-recurse+exitthendrop1;utime41fib.crutime2swapd-."timeelapsed"d."us"cr如果在windows下使用mingw编译当前的TinyCC,嵌入C脚本会报错:tcc:file7c/ProgramFiles/t川cbtccl.a'notfoundDougCurrie在tcc的邮件列表里面提供了一个补丁:HereiswhatIdid(andreportedtothemailinglist)lastFebruary,sothepatchmaynotbeaccurateformorerecentversions,buttheissuesarethesameIhavebeenabletocreatealibtccdllforWinXPusingMinGW/MSYS;thechangesthatwerenecessarywereveryminor.PerhapsthisdescriptionwillhelpothersuselibtcconWindows.First,asmallbugtoreport:Intcc.cthefunctiontcc_basename()followstheline:#if!defined(LIBTCC)butthefunctiontcc_basename()isusedinpe_build_exports()intccpe.c--movingthe#iflinebelowthefunctiontcc_basename()eliminatesalinkerrorbuildinglibtcdllinPEtargetmode.Second,configuringandmakingtccwithMSYSplacesapathnameinconfighinMSYSformat.Forexample,Ipassedtheargument--prefix=/c/Dev/tcctoconfigure;thispathwasgoodforbuildingtcc.exeanddidn'tcontainanyspaces,unlikethedefaultpath.Thiscreatestheline#defineCONFIG_TCCDIR"/c/Dev/tcc"inconfighManuallychangingthislinet