4 ms·
With a decent implementation you can write performant code in a dynamic language. An example in Common Lisp using the SBCL compiler on an Intel Core2 Duo @ 2.6
by agentultra 15y ago
With a decent implementation you can write performant code in a dynamic language.
An example in Common Lisp using the SBCL compiler on an Intel Core2 Duo @ 2.66GHz w/ 6G of RAM:
CL-USER> (defparameter *nums* (make-array 3000000 :element-type 'float :initial-element 0.0))
*NUMS*
CL-USER> (dotimes (i (length *nums*)) (setf (aref *nums* i) (random 30.0)))
NIL
CL-USER> (time (reduce #'+ *nums*))
Evaluation took:
0.375 seconds of real time
0.379975 seconds of total run time (0.379975 user, 0.000000 system)
[ Run times consist of 0.197 seconds GC time, and 0.183 seconds non-GC time. ]
101.33% CPU
1,000,511,208 processor cycles
96,010,096 bytes consed
4.4951772e7
CL-USER>
C isn't always the answer (thought it often is a pretty good default).
- jwr 15y agoI think it's naïve to speak of "performant code" in general. Sure, I used SBCL (and CMUCL, and AllegroCL) to get blazing double-type single-cpu performance. But then I wanted to make use of multiple cores, which is when I ran into a brick wall. Things are better with SBCL now than they used to be, but people still run into bugs related to multithreading, not to mention that CL has little support for concurrent programming. The definition of "performance" is different for every application. For some, it's multiplying long vectors of doubles. For others, it's making use of 16 cores for complex data structures operations. For others it's about servicing tens of thousands of mostly idle TCP connections (tried to do that with AllegroCL, failed). For others yet, it's about achieving consistent response times, which means concurrent and nearly pauseless GC.
- agentultra 15y agoIn other words, choose the right tool for the job. However I think the OP was comparing dynamic vs static languages. Ey made a prototype physics simulation in Python whose source code was nice to read but performed terribly. Ey then decided to write it in C (not a bad choice mind you). It seemed to me that the OP found the readability of Python (and dynamic languages in general) a useful trait to have while lamenting that their implementations were too slow to be practical for eirs purposes. Therefore I proposed an example of a dynamic language with the property of being easy to read while being fast in implementation. Otherwise I think we violently agree.
- yvdriess 15y agoYou'll get an extra factor of perfomance if you do a (loop for rand across *nums* summing rand) instead of using the generic reduce.
- betterorbutter 15y agoif you are for perfomance don't use reduce, use loop and time get reduced from 0.38 seconds to 0.049 seconds. (time (loop for x across *nums* sum x)) Evaluation took: 0.049 seconds of real time