Live data from Hacker News

How many lines of C it takes to execute a + b in Python

codeconfessions.substack.com

201–210 of 224 posts

Re: How many lines of C it takes to execute a + b in Python

#201
post #191
post #183

Earlier quoted context omitted.

Better than CPython, regardless of how you put it. EDIT: Also to note, those languages powered whole graphical single workstations, with microcoded CPUs + JIT. "Efficient implementation of the smalltalk-80 system" https://dl.acm.org/doi/10.1145/800017.800542 https://computerhistory.org/blog/introducing-the-smalltalk-z... "Self-Confidence: How SELF Became a High-Performance Language" https://www.cs.cornell.edu/courses…

vs CPython https://benchmarksgame-team.pages.debian.net/benchmarksgame/... vs Node https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

CPython is the one being compared here, and besides Pharo, better use an industrial strength one, like Cincom Smalltalk.

Re: How many lines of C it takes to execute a + b in Python

#202
post #191

Earlier quoted context omitted.

vs CPython https://benchmarksgame-team.pages.debian.net/benchmarksgame/... vs Node https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Exactly. Comparing with CPython is too easy and arguably unfair, Smalltalk should be compared with JS instead and I think it has no chance in that setting.

Why should it be compared?

We are not comparing Smalltalk JITs to Javascript JITs.

The whole point of this conversation is CPython refusing to add one, and the lame excuses regarding its dynamic capabilities, when more dynamic languages have had a JIT for decades.

Re: How many lines of C it takes to execute a + b in Python

#203
post #190

Earlier quoted context omitted.

Is there any direct comparison though? Because it can be alternatively argued that these dynamic languages needed new JIT techniques for performance, but they especially work well for more constrained languages like JS. I don't think Smalltalk was ever a good fit for number crunching, for example.

So if one was "Prototyping a Real-Time Embedded System in Smalltalk" one might 'improve frequently invoked methods by recoding, possibly as “primitive” functions in a lower level language such as C or assembler'. https://dl.acm.org/doi/pdf/10.1145/74878.74904

CPython is up to date with one specific Smalltalk implementation in 1987, when an ESP32 has better hardware resources than those systems, what a great achievement!

Re: How many lines of C it takes to execute a + b in Python

#204
post #202

Earlier quoted context omitted.

Exactly. Comparing with CPython is too easy and arguably unfair, Smalltalk should be compared with JS instead and I think it has no chance in that setting.

Why should it be compared? We are not comparing Smalltalk JITs to Javascript JITs. The whole point of this conversation is CPython refusing to add one, and the lame excuses regarding its dynamic capabilities, when more dynamic languages have had a JIT for decades.

First, because CPython had more concerns than what Smalltalk implementations have, so such comparison would be unfair to Python. (See my topmost comment for example.)

Second, my question was about the possibility that Smalltalk and others were unbearably slow without JIT, so JIT was not a matter of choice for them. I'm not aware of Smalltalk implementations that don't have JIT, so it would be easier to compare Smalltalk with another well-optimized JIT implementation instead---in this case JS.

Re: How many lines of C it takes to execute a + b in Python

#205

Earlier quoted context omitted.

If you want to be return absolutely any value from an iterator, an exception is indeed a reasonable choice though. Python generators came in much later, unlike JS for example.

If that is indeed a requirement, you let your iterator have an .at_end() test instead of trying to shoehorn it into the return value. Or have something like C++'s std::optional or Rust's Option. Or a special EndOfIteration object that you cannot return from an iterator (is that really so bad?). Iteration is extremely common, and should thus be based on as simple primitives as possible if you want things to go fast.

I believe the original PEP [1] answers almost all questions. The only option not covered would be probably an "optional" type, but it is even easier to answer: any such type has to be heap-allocated in the Python memory model, so a mere iteration could've caused a lot of redundant memory allocations.

[1] https://peps.python.org/pep-0234/#rationale

Re: How many lines of C it takes to execute a + b in Python

#206
post #4

A while back someone posted their patch to cpython where they replaced the hash function with a fast one and claimed this dramatically sped up the whole Python runtime. They claimed that the hash function was used constantly —e.g. 11 times in print("hello world")—because it's used to look up object properties. Apparently the default implementation is not optimized for performance but for security, just in case the so…

This may be a somewhat uninformed opinion, but I think CPython is just straight up not particularly good software. There are a million and one optimizations that other major scripting runtimes (V8, LuaJIT, PyPy, Ruby YJit etc.) have had for years that CPython is lacking. This is by design though. CPython has never been focused on performance, that's why it's not even JIT. It optimizes for simplicity and easy interope…

Is there any comprehensive comparison and benchmark of intepreted languages or languages with a REPL and analysis of how each interpreter handles common operations?

Re: How many lines of C it takes to execute a + b in Python

#207
post #113

Earlier quoted context omitted.

I agree with that estimate, I think it was really the idea of Python to be less than "good" by design. I mean one doesn't need more than: >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit to see. They have that special handling, but they still don't want to let you out, because... IMO, they just want to be annoying. When a solution could be something like: Note: exit() is needed in scripts. In this prompt Ctrl-D (i.e.…

There has been discussion of this change a few times, e.g. https://bugs.python.org/issue44603 I generally agree with your overall sentiment, but I think it's important to note that the behavior is _not_ special handling; it's just the normal `repr` behavior at the REPL, where `exit` is an object like any other, and `repr(exit)` is that message.

Whoever types exit in REPL will never care what "repr(exit)" does.

Python has a lot excuses about the need to remain "consistent" but the reality isn't so:

    >>> x = open( "/tmp/whatever123", "w" )
    >>> close( x )
    Traceback (most recent call last):
      File "", line 1, in 
    NameError: name 'close' is not defined. Did you mean: 'cosh'?
    ...    
    >>> x.close()
    >>>
    >>> x = "tttt"
    >>> x.len()
    Traceback (most recent call last):
      File "", line 1, in     
    ...
    >>> len( x )
    4

Re: How many lines of C it takes to execute a + b in Python

#208

Earlier quoted context omitted.

I wonder what percent of this audience got the tootsie-roll reference. Does anyone under 40 know it?

I'm in Gen Z and I think I got it. The Tootsie pop commercial with the owl used to play all the time on Canadian TV.

Onne... Two-hooo!

Re: How many lines of C it takes to execute a + b in Python

#209
post #192

Earlier quoted context omitted.

> Most languages with enough optimization works can be made performant enough that it's no slower than 10x C. Maybe if we take the slowest C program, CPython no slower than 50x ? https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

CPython had many other concerns besides from performance, and PyPy is much closer to my quote I believe.

fwiw "How many lines of C it takes to execute a + b in Python" was explicitly about CPython.

fwiw PyPy doesn't seem to have been released in "the late 1990s".

Re: How many lines of C it takes to execute a + b in Python

#210
post #203
post #190

Earlier quoted context omitted.

So if one was "Prototyping a Real-Time Embedded System in Smalltalk" one might 'improve frequently invoked methods by recoding, possibly as “primitive” functions in a lower level language such as C or assembler'. https://dl.acm.org/doi/pdf/10.1145/74878.74904

CPython is up to date with one specific Smalltalk implementation in 1987, when an ESP32 has better hardware resources than those systems, what a great achievement!

One way Smalltalk was made a better fit for number crunching: primitives.
Post reply on HN