TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Timing data comparing CClasp to C++, SBCL and Python

45 pointsby OopsCriticalityalmost 10 years ago

5 comments

jlaroccoalmost 10 years ago
People are missing the point with the Python code. The C++ code and the Lisp code aren&#x27;t particularly optimized, either. The point of the benchmark is to compare the relative speeds of roughly the same Fibonacci code out of the box.<p>On SBCL, a memoized recursive fibonacci is about twice as fast as the Lisp code given also running in SBCL on my machine, for example.<p>I&#x27;m more suspicious about why the C++ code is so slow.<p>Edit: I wrote my own C++ Fib code and tried benchmarking it outside of Clasp (<a href="https:&#x2F;&#x2F;gist.github.com&#x2F;jl2&#x2F;4d74958b02b3caea2f5c" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;jl2&#x2F;4d74958b02b3caea2f5c</a>). It routinely ran in less than 0.005 seconds, which seemed too fast, so I looked at the assembly output. AFAICT, the compiler is smart enough to realize fib() has no side effects and is &quot;pure&quot;, and is computing the value at compile time, reducing the function call to essentially be myfib = 8944394323791464. It almost seems like an unfair comparison, but since it&#x27;s comparing compiler performance, I think it&#x27;s relevant information.
评论 #9988392 未加载
Fede_Valmost 10 years ago
I was a bit curious, so I did a short experiment:<p><a href="http:&#x2F;&#x2F;nbviewer.ipython.org&#x2F;urls&#x2F;dl.dropbox.com&#x2F;s&#x2F;l9naqibqytv8vjt&#x2F;Numba_Fib.ipynb" rel="nofollow">http:&#x2F;&#x2F;nbviewer.ipython.org&#x2F;urls&#x2F;dl.dropbox.com&#x2F;s&#x2F;l9naqibqyt...</a><p>Using numba, and adding a one line decorator to the function (without any changes whatsoever) we get around 2 orders of magnitude speed up.<p>Note - this doesn&#x27;t involve any fancy re-writing, annotating, etc, you literally just add a decorator.<p>Writing really fast numerical code in Python is very easy. There&#x27;s absolutely no reason not to use numba if you have small functions that just do number crunching. numba can even inline other numba functions - so you don&#x27;t even pay the function call overhead.
评论 #9987381 未加载
评论 #9987595 未加载
评论 #9987623 未加载
评论 #9989197 未加载
评论 #9987556 未加载
robmccollalmost 10 years ago
In Python 2.7, shouldn&#x27;t you be using xrange() rather than range()? xrange() is a generator whereas range() will actually create the entire list and iterate it.<p>In case anyone isn&#x27;t aware: in Python 3, range()&#x27;s implementation was effectively replaced with that of xrange().
评论 #9987274 未加载
评论 #9989202 未加载
wtbobalmost 10 years ago
CClasp is looking really, really interesting. I&#x27;m still enjoy SBCL, but on the right project—why not try CClasp?
rchalmost 10 years ago
Cython would make sense in this context (~19 seconds for me).
评论 #9987537 未加载
评论 #9987308 未加载
评论 #9987359 未加载
评论 #9987982 未加载