下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、python 中嵌入 C 语言脚本借助 Cinpy 和 C 语言解释器 TinyCC ,可以在 python 程序里面直 接嵌入 C 语言片断、不经编译直接使用 C 编写的函数了。 win2k 平台上,简单的测试对比数据如下(递归方法计算第四十项兔 子数列 fib ( 40)语言 实现 时间(单位:秒) 评 python 官方 python 纯 python fib 函数 568.718 天啊 使用 psyco 加速的 python fib 函数17.922 比较接近,还行 使用 swig 直接转换的 C 语言编写的模块13.453 使用 Cinpy 嵌入 fib 函数11.532VC6 速度
2、优化编译的可执行文件5.562 编译的可执行文件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.hx1964th lg fib.hx fib.cmingw -O2 fib.c -o fib.exe110Gforth-fast fib.gfth14.719 不错,不过不是说和 C 的速度可以比嘛? 怎么也就是优化的 python 的速度啊
3、注:其余源程序freebasic function fib(x as integer) as integer if x<=1 thenreturn 1elsereturn fib(x-1) + fib(x-2)end ifend functiondim starttime, endtime as double dim res as integerstarttime=timer res=fib(40) endtime=timerprint "fib(40)= "resprint "time elapsed: " (endtime-startt
4、ime); " s"4th : fib ( x - y )dup 2 > ifdup 1 - recurseswap 2 - recurse + exitthendrop 1 ;time41 fib . crtimeswap -." time elapsed " . ." : fib ( x - y )dup 2 > ifdup 1 - recurseswap 2 - recurse +exitthendrop 1 ;utime41 fib . crutime2swap d." time elapsed &
5、quot; 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
6、 the issues 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 this description will help others use libtcc on Windows.First, a small bug to report:In tcc.c the function tcc_basename() follows the line:#if !define
7、d(LIBTCC)but the function tcc_basename() is used in pe_build_exports() in tccpe.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 in config.h in MSYS format. For exam
8、ple, I passed the argument -prefix=/c/Dev/tcc to configure; this path was good for building tcc.exe and didn't contain any spaces, unlike the default path. This creates the line #define CONFIG_TCCDIR "/c/Dev/tcc" in config.h. Manually changing this line to #define CONFIG_TCCDIR "C
9、:/Dev/tcc" enables libtcc.dll to find the include files and libraries once the library is built. The application tcc.exe avoids this problem by setting tcc_lib_path from the application's directory at startup. A similar solution could be used for the library using DllMain. So, after configu
10、re, 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.c TCC_TARGET
11、_PE and DLL location of library files. Regards,e+ tcc.cTue 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 D
12、llMain(void * hinstDLL, unsigned long fdwReason, voidlpvReserved)+if (fdwReason = 1/*DLL_PROCESS_ATTACH*/)+/* on win32, as implemented in main()+we suppose the lib and includes are at the location of thislibrary+*/+static char path1024;+char *p, *d;+GetModuleFileNameA(hinstDLL, path, sizeof path);+p = d = strlwr(path);+w
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护理职业素养提升与就业准备
- 护理技术操作培训:基础护理技能
- 护理管理中的财务管理
- 护理人力资源管理与员工关系
- 部编版二年级语文下册《祖先的摇篮 第2课时》
- 护理教学比赛资源整合
- 护理礼仪的团队协作
- 客户服务经理职场新人面试宝典
- 快消品行业区域经理工作全解析
- 快消品市场策划面试要点及技巧
- OpenClaw基础概念与架构
- 2026广西桂林漓佳金属有限责任公司招聘10人考试参考题库及答案解析
- 6 会摇尾巴的狼 课件(共24张)
- 2025至2030中国医养结合模式养老服务供需匹配度调研报告
- 2026广东江门职业技术学院管理教辅人员招聘4人备考题库及一套答案详解
- 深度解析(2026)《NBT 10558-2021压力容器涂敷与运输包装》
- TAS倍智行测题库
- 2025年山东省春季高考数学试卷试题真题(含答案解析)
- 黑龙江省哈尔滨师大附中2025-2026学年高一上学期期末语文试卷(含答案)
- 新课改下高中篮球社团开展现状调查与研究
- 2026年湖南大众传媒职业技术学院单招职业技能考试备考试题带答案解析
评论
0/150
提交评论