




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
python中嵌入C语言脚本 借助Cinpy和C语言解释器TinyCC,可以在python程序里面直接嵌入C语言片断、不经编译直接使用C编写的函数了。 win2k平台上,简单的测试对比数据如下(递归方法计算第四十项兔子数列fib(40)语言实现时间(单位:秒)评python官方python 2.4.3纯python fib函数568.718天啊使用psyco加速的python fib函数17.922比较接近,还行使用swig直接转换的C语言编写的模块13.453使用Cinpy嵌入fib函数11.532CVC6速度优化编译的可执行文件5.562TinyCC 0.9.23编译的可执行文件6.719解释执行6.813FreeBASICfbc 0.16b编译的可执行文件(-arch 486)8.022编译的可执行文件(-arch 686)7.619forth4th 3.5a24th cx fib.4th277 这个表现太失望了 4th csv fib.4th fib.hx4th lx fib.hx 1964th lg fib.hx fib.cmingw -O2 fib.c -o fib.exe 110gforth-0.6.2Gforth-fast fib.gfth14.719不错,不过不是说和C的速度可以比嘛? 怎么也就是优化的python的速度啊 注:其余源程序freebasic function fib(x as integer) as integerif x<=1 thenreturn 1elsereturn fib(x-1) + fib(x-2)end ifend functiondim starttime, endtime as doubledim res as integerstarttime=timerres=fib(40)endtime=timerprint fib(40)= ;resprint time elapsed: ; (endtime-starttime); s 4th : fib ( x - y )dup 2 > ifdup 1 - recurseswap 2 - recurse +exitthendrop 1 ;time41 fib . crtimeswap -. time elapsed . . s crgforth-0.6.2 : fib ( x - y ) dup 2 > if dup 1 - recurse swap 2 - recurse + exit then drop 1 ;utime41 fib . crutime2swap d- . time elapsed d. . us cr 如果在windows下使用mingw编译当前的TinyCC,嵌入C脚本会报错:tcc: file /c/Program Files/tcc/libtcc1.a not foundDoug Currie在tcc的邮件列表里面提供了一个补丁: Here is what I did (and reported to the mailing list) last February,so the patch may not be accurate for more recent versions, but theissues are the same.I have been able to create a libtcc.dll for WinXP using MinGW/MSYS;the changes that were necessary were very minor. Perhaps thisdescription will help others use libtcc on Windows.First, a small bug to report:In tcc.c the function tcc_basename() follows the line:#if !defined(LIBTCC)but the function tcc_basename() is used in pe_build_exports() intccpe.c - moving the #if line below the function tcc_basename()eliminates a link error building libtcc.dll in PE target mode.Second, configuring and making tcc with MSYS places a pathname inconfig.h in MSYS format. For example, I passed the argument-prefix=/c/Dev/tccto configure; this path was good for building tcc.exe and didntcontain any spaces, unlike the default path. This creates the line#define CONFIG_TCCDIR /c/Dev/tccin config.h. Manually changing this line to#define CONFIG_TCCDIR C:/Dev/tccenables libtcc.dll to find the include files and libraries once thelibrary is built. The application tcc.exe avoids this problem bysetting tcc_lib_path from the applications directory at startup. Asimilar solution could be used for the library using DllMain.So, after configure, fix CONFIG_TCCDIR in config.h and make.Finally, the library libtcc.dll can be built with the MSYS command:gcc -O2 -shared -Wall -Wl,-export-all-symbols /-mpreferred-stack-boundary=2 /-march=i386 -falign-functions=0 -fno-strict-aliasing /-DTCC_TARGET_PE -DLIBTCC -o libtcc.dll tcc.cBelow is a diff of tcc-0.9.23 tcc.c and the changes for LIBTCC withTCC_TARGET_PE and DLL location of library files.Regards,e$ diff -u ./tcc-0.9.23-o/tcc.c tcc.c- ./tcc-0.9.23-o/tcc.c Fri Jun 17 18:09:15 2005+ tcc.c Tue Feb 28 17:03:44 2006 -10157,8 +10157,6 flag_name, value); -#if !defined(LIBTCC)- /* extract the basename of a file */ static const char *tcc_basename(const char *name) -10175,6 +10173,35 return p; +#if defined(LIBTCC)+#ifdef WIN32+int _stdcall DllMain(void * hinstDLL, unsigned long fdwReason, void *lpvReserved)+ if (fdwReason = 1/*DLL_PROCESS_ATTACH*/)+ + /* on win32, as implemented in main()+ we suppose the lib and includes are at the location of this library+ */+ static char path1024;+ char *p, *d;+ GetModuleFileNameA(hinstDLL, path, sizeof path);+ p = d =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离婚协议书执行监督与违约责任追究规范
- 离婚协议范文:全面流程解析及赡养费计算方法
- 离婚协议书样本:共同债务处理及财产分配方案
- 离婚协议书范本与婚后共同债务承担及财产分配方案
- 离职补偿协议范本:针对特殊岗位员工及技能转移
- 文化创意产业园区空置土地出租及运营管理合同
- 建筑装修砌体抹灰劳务分包合同范本
- 人工智能研发项目技术人才派遣及创新成果分享合同
- 消防设备定期检修、保养及隐患排查合同
- 生物医药私募股权投资基金委托管理协议
- 包装车间基础知识培训课件
- 2025年贵州建筑中级试题及答案
- 2025年全科医师转岗培训理论必刷试题库及答案
- 古代服饰复原与租赁服务创新创业项目商业计划书
- 量产产品管理办法
- 河北社区工作管理办法
- 超声内镜检查及护理配合
- 数字人文与档案重构-洞察及研究
- 关于密码的课件
- 起重机安全生产责任制
- 小儿腹泻患者的健康宣教
评论
0/150
提交评论