Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are a lot of dynamically typed languages that are significantly faster than python. Late binding issues can be effectively worked around.


Do you have an example of a dynamically typed language where, say, addition of two lists of doubles would be significantly faster than in Python?


Assuming you mean pairwise addition, Pharo achieves over twice Python speed, in my laptop.

Python version:

  from random import randrange
  from time import time
  
  def main():
      L = [float(randrange(2**52, 2**53)) for _ in range(20000000)]
      M = [float(randrange(2**52, 2**53)) for _ in range(20000000)]
  
      t0 = time()
      N =  [ x+y for x,y in zip(L, M) ]
      print('Concluded in', round(1000*(time() - t0)), 'millisec.')
  
  main()
Results:

  Python 3.10.5 (main, Jun  9 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux
  Type "help", "copyright", "credits" or "license()" for more information.
  
  ============ RESTART: /run/media/user/KINGSTON/benchmark_doubles.py ============
  Concluded in 1904 millisec.
Pharo 10 version:

  | L M N t0 |
  
  Transcript clear.
  L := (1 to: 2e7) collect: 
   [ :each | (( 2 raisedTo: 52 ) to: ( 2 raisedTo: 53 )) atRandom asFloat ].
  M := (1 to: 2e7) collect: 
   [ :each | (( 2 raisedTo: 52 ) to: ( 2 raisedTo: 53 )) atRandom asFloat ].
  t0 := DateAndTime now.
  M := L with: M collect: [ :x :y | x + y ].
  Transcript
    show: 'Concluded in '
        ,
            ((DateAndTime now - t0) asMilliSeconds asInteger ) asFloat asString
        , ' millisec.';
    cr.
Results:

  Concluded in 914.0 millisec.


You mean concatenating the lists or pairwise addition?

I don't expect the former to be slow in python as it would be a primitive implemented in C (although even a simple lisp interpreter can have an advantage here by just concatenating the conses).

For the latter, any language runtime capable of inference should be able to optimize it.


I would expect this microbenchpark in particular to be as fast in LuaJIT as it would be in C, without the risk of undefined behavior if the array boundaries are improperly calculated.


Doesn't that sort of operation become very fast in JS after a few runs?


Probably most Common Lisp implementations.


LuaJIT.


Racket




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: