(defun billion-test () (setq i 0) (loop while (< i 100) do (setq i (+ i 1)))) (billion-test) (print "done")
慢。 比我曾经写过的任何微不足道的程序都慢。 这是所花费的时间
用我有的解释器(gcl和clisp)运行。
Compiled Uncompiled GNU Common Lisp(gcl) 270-300s 900-960s Clisp 280-300s 960-1647s
我使用这个Python代码来计算Clisp的时间,并使用系统时间近似计算时间
与gcl因为你不能从命令提示符运行它。
import sys import time import os start=time.time() os.system(" ".join(sys.argv[1:])) stop=time.time() print "n%.4f secondsn"%(stop-start)
以下是来自其他语言的while循环的比较:
Kawa scheme 220.3350s Petite chez 112.827s C# 1.9130s Ruby 31.045s Python 116.8600s 113.7090s(optimized) C 2.8240s 0.0150s(optimized) lua 84.6970s
我的假设是loop while <condition> do是Lisp相当于一段while
循环。 我对这些1647s(25+ min)有一些怀疑,我正在看那些东西
时间,它可能会减慢执行,但几乎800s ? 我不知道。
这些结果很难相信。 据norvig Lisp
比Python快3到85倍。 从我所得到的,最合乎逻辑的来看
对这种缓慢执行的解释是Windows中的Clisp和gcl有某种types
的bug减缓了大的迭代。 你怎么问,我不知道? Sooo,我的问题是, 为什么这么慢 ?
有人得到这样的东西吗?
测量Visual C ++中操作速度的最佳方法
全球自创的对象
我已经安装了包:pywinauto成功与“pip安装pywinauto”,但它总是失败,为什么?
将高级function添加到tkinter文本小部件
如何获得长途径的安全细节?
更新1:
我跑了Joswigs的节目并且得到了这些结果:
compiled uncompiled gcl 0.8s 12mins clisp 5mins 18mins
gcl编译好的程序, clisp却给出了这个警告:
;; Compiling file C:mine.cltest.cl ... WARNING: in BILLION-TEST in lines 1..8 : FIxnuM-SAFETY is not a valid OPTIMIZE quality. 0 errors,1 warning ;; Wrote file C:mine.cltest.fas ;; clisp [2]> (type-of 1000000000) (INTEGER (16777215)) ;;gcl (type-of 1000000000) FIxnuM
猜猜这可能是花了一分多钟的原因。
更新2:
我想我会再尝试一下另一个实现来确认
这是真正的比较,减缓它。 我获得了sbcl
对于Windows并再次运行该程序:
* (print most-positive-fixnum) 536870911 * (compile-file "count-to-billion.cl") ; compiling file "C:/mine/.cl/count-to-billion.cl" (written 09 OCT 2013 04:28:24 PM): ; compiling (DEFUN BILLION-TEST ...) ; file: C:/mine/.cl/count-to-billion.cl ; in: DEFUN BILLION-TEST ; (OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0) (FIxnuM-SAFETY 0)) ; ; caught WARNING: ; Ignoring unkNown optimization quality FIxnuM-SAFETY in: ; (OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0) (FIxnuM-SAFETY 0)) * (load "count-to-billion")
我希望我能告诉你多久,但我从来没有看到它的结局。 我等了
2小时,看了一集吸血鬼日记(嘿嘿),还没有完成。
我期待它比Clisp更快,因为它的MOST-POSITIVE-FIxnuM是,更好
正。 我担保缓慢的执行点,因为只有gcl可以拉
closures不到一分钟的运行。
使用gcl运行Rörd的代码:
(time (loop with i = 0 while (< i 1000000000) do (incf i))) gcl with Rords's code: >(load "count-to-billion.cl") Loading count-to-billion.cl real-time : 595.667 secs run time : 595.667 secs >(compile-file "count-to-billion.cl") OPTIMIZE levels: Safety=0 (No runtime error checking),Space=0,Speed=3 Finished compiling count-to-billion.cl. #p"count-to-billion.o" >(load "count-to-billion") Loading count-to-billion.o real time : 575.567 secs run time : 575.567 secs start address -T 1020e400 Finished loading count-to-billion.o 48
更新3:
(defun billion-test () (loop with i fixnum = 0 while (< i 1000000000) do (incf i)))
令人惊讶的是,它运行速度与Joswig的不同之处在于关键字fixnum和:
gcl的输出:
real time : 0.850 secs run time : 0.850 secs
sbcl的输出(跑了大约半秒钟,吐出来):
debugger invoked on a TYPE-ERROR in thread #<THREAD "main thread" RUNNING {23FC3A39}>: The value 536870912 is not of type FIxnuM.
clisp的输出:
Real time: 302.82532 sec. Run time: 286.35544 sec. Space: 11798673420 Bytes GC: 21413,GC time: 64.47521 sec. NIL
活动窗口上是否有Windows系统事件更改?
Python ctypes – GetVersionEx函数获取0
如何更改.net Web应用程序中的默认文化设置?
在窗户上使用select()和STDIN?
启动时间
未申报的变量
没有类型声明
编译器没有告诉优化
在32位机器/实现1000000000可能不是一个fixnum,请参阅变量MOST-POSITIVE-FIxnuM
可能<与32位机器上的bignum比较 – >更好地计数到0
执行速度慢
一个64位的Common Lisp应该有更大的fixnums,我们可以使用简单的fixnum计算。
在带有2 GHz Intel i7的MacBook Air笔记本电脑上的64位LispWorks上,我获得了未经优化的代码,稍微在2秒内运行。 如果我们添加声明,它会更快一点。
(defun billion-test () (let ((i 0)) (declare (fixnum i) (optimize (speed 3) (safety 0) (debug 0)) (inline +)) (loop while (< i 1000000000) do (setq i (+ i 1))))) CL-USER 7 > (time (billion-test)) Timing the evaluation of (BILLION-TEST) User time = 0.973 System time = 0.002 Elapsed time = 0.958 Allocation = 154384 bytes 0 Page faults NIL
64位SBCL需要0.3秒。 所以它更快。
有了GCL,你应该可以在32位机器上获得更好的结果。 在这里,我使用了32位ARM处理器(三星Exynos 5410)上的GCL。 在ARM机器上有十亿与GCL仍然是一个fixnum。
>(type-of 1000000000) FIxnuM >(defun billion-test () (let ((i 0)) (declare (fixnum i) (optimize (speed 3) (safety 0) (debug 0)) (inline +)) (loop while (< i 1000000000) do (setq i (+ i 1))))) BILLION-TEST >(compile *) Compiling /tmp/gazonk_23351_0.lsp. Warning: The OPTIMIZE quality DEBUG is unkNown. End of Pass 1. End of Pass 2. OPTIMIZE levels: Safety=0 (No runtime error checking),Speed=3 Finished compiling /tmp/gazonk_23351_0.lsp. Loading /tmp/gazonk_23351_0.o start address -T 0x7a36f0 Finished loading /tmp/gazonk_23351_0.o #<compiled-function BILLION-TEST> NIL NIL
现在你可以看到GCL也是相当快的,即使是在较慢的ARM处理器上:
>(time (billion-test)) real time : 0.639 secs run-gbc time : 0.639 secs child run time : 0.000 secs gbc time : 0.000 secs NIL
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。