python中嵌入C语言脚本.pdfVIP

  • 7
  • 0
  • 约4.49千字
  • 约 7页
  • 2020-09-10 发布于天津
  • 举报
p y t h o n 中 嵌 入 C 语 言 脚 本 借助 Cinpy 和 C 语言解释器 TinyCC ,可以在 python 程序里面直接嵌 入 C 语言片断、不经编译直接使用 C 编写的函数了。 win2k 平台上,简单的测试对比数据如下(递归方法计算第四十项兔子数 列 fib (40 ))语言 实现 时间 (单位:秒) 评 python 官方 python 纯 python fib 函数 天啊 使用 psyco 加速的 python fib 函数 比较接近,还行 使用 swig 直接转换的 C 语言编写的模块 使用 Cinpy 嵌入 fib 函数 C VC6 速度优化编译的可执行文件 编译的可执行文件 解释执行 FreeBASIC fbc 编译的可执行文件( -arch 486) 编译的可执行文件( -arch 686) forth 4th 4th cx 277 这个表现太失望了 4th csv 4th lx 196 4th lg mingw -O2 -o 110 不错,不过不是说和 C 的速度可以比嘛? 怎么也就是优化的 python 的速度啊 注: 其余源程序 freebasic function fib(x as integer) as integer if xlt;=1 then return 1 else return fib(x-1) + fib(x-2) end if end functiondim starttime, endtime as double dim res as integerstarttime=timer res=fib(40) endtime=timer print fib(40)= ;res print time elapsed: ; (endtime-starttime); s 4th : fib ( x -- y ) dup 2 gt; if dup 1 - recurse swap 2 - recurse + exit then drop 1 ;time41 fib . crtime swap - . time elapsed . . s cr : fib ( x -- y ) dup 2 gt; if dup 1 - recurse swap 2 - recurse + exit then drop 1 ; utime41 fib . crutime 2swap d- . time elapsed d. . us cr 如果在 windows 下使用 mingw 编译当前的 TinyCC ,嵌入 C 脚本会报错: tcc: file /c/Program Files/tcc/ not found Doug 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 the issues are the same... I have been able to create a for WinXP using MinGW/MSYS; the changes that were necessary were very minor. Perhaps this description

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档