3 ms·
> The explanation is that Python features heavy dynamism JavaScript too, any function can be dynamically changed at any time, but its function calls are 30x fa
by Aardwolf 4y ago
> The explanation is that Python features heavy dynamism
JavaScript too, any function can be dynamically changed at any time, but its function calls are 30x faster (roughly, I measured it just now with a for loop doing 100 million function calls, which took 0.5s in JS, 15s in python)
This is a realistic scenario if you want to run e.g. a custom statistics function on a large array in python so it can be annoying (and yes numpy can do things but that's no reason to keep the main language encouraging less readable code where you don't define separate functions)
- BiteCode_dev 4y agoHence the "So it's something that had be delayed.", and not "this is something impossible". Javascript has the benefit of having billions of dollars allocated to it from Google/Microsoft/Apple to hire dozen of amazing engineers full time over decades to work on it. Python has existed since 1994, yet in 2011, the Python Software Fundation budget was less than $40K: https://pyfound.blogspot.com/2012/01/psf-grants-over-37000-to-python.html https://pyfound.blogspot.com/2012/01/psf-grants-over-37000-t... We are talking a difference of funding of 6 order of magnitudes. Not to mention one is a language that has to stand on its own, the second has an accidental monopoly on the most popular plateform in the world. So it had to be delayed, unlike for JS.
- SemanticStrengh 4y ago> Python has existed since 1994, yet in 2011, the Python Software Fundation budget was less than $40K Exact, as usual it is mainly a question of human resources. Hence why I advocate for Python switching to GraalPython as the default runtime, it would enable much better performance in the next few years. Also, I'm pretty sure cpython devs should ask Google/OpenAI/MicrosoftAI funding, how many millions can they waste on useless projects while not improving the core bottleneck..
- BiteCode_dev 4y agoYou are asking for the rarest thing of all, a geek and volounteer worker that is also good at dealing with big entities and comfortable with managing money.
- ptx 4y ago> its function calls are 30x faster (roughly, I measured it just now with a for loop doing 100 million function calls, which took 0.5s in JS, 15s in python) Your benchmark also measures iterators and boxed integers, which were not in the JavaScript version, so it's not clear how much of the difference is due to function call overhead. (Of course, it certainly doesn't help Python's performance that there's no simple way to do loops without iterators and integers without boxing. It would be nice if a future version could optimize the abstractions away.)
- SemanticStrengh 4y agoJS integers are value types unlike Java?!
- ptx 4y agoOn second thought, I'm not sure. Can you observe the number's object identity like you can in Python? Does JavaScript have to allocate a new Number object for each "i++"? My point was that the Python version of Aardwolf's function call benchmark [1] is definitely using iterators and boxing all numbers, so it's doing a lot more than just calling a function, and the Java equivalent would look something like this: Long f(Integer x) { return new Long(x.longValue() * x.longValue()); } // ... Double v = new Double(0.0); Iterator<Integer> range = IntStream.range(0, 100000000).iterator(); while (range.hasNext()) { Integer i = range.next(); v = new Double(v.doubleValue() + f(i).doubleValue()); } [1] https://news.ycombinator.com/item?id=31427506 https://news.ycombinator.com/item?id=31427506