Re: Static typing [was Re: Python and the need for speed]

2017-06-21 Thread Paul Rubin
Gregory Ewing writes: > A JIT compiler works by observing the actual values To be pedantic, that's called a "tracing JIT". Other runtime code generation is also frequently called JIT compilation even when it's fairly stupid combining of assembly code templates, or

Re: Static typing [was Re: Python and the need for speed]

2017-04-18 Thread Gregory Ewing
Steve D'Aprano wrote: You seem to be describing a *tracing JIT* compiler. Well, yes, but it seems to me that a JIT compiler that *doesn't* use tracing is just an AOT compiler that you happen to run immediately before executing the program. Cython doesn't do any of that -- it's just a plain,

Re: Static typing [was Re: Python and the need for speed]

2017-04-18 Thread Steve D'Aprano
On Tue, 18 Apr 2017 03:43 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> I'm not sure why the Cython devs maintain this is not a JIT compiler. >> Perhaps I misunderstand something. > > A JIT compiler works by observing the actual values taken on > by variables at run time, and if it notices

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Gregory Ewing
Steve D'Aprano wrote: I'm not sure why the Cython devs maintain this is not a JIT compiler. Perhaps I misunderstand something. A JIT compiler works by observing the actual values taken on by variables at run time, and if it notices that a particular variable seems to always have a particular

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Steve D'Aprano
On Mon, 17 Apr 2017 08:52 pm, Steve D'Aprano wrote: > but research does continue into using gradual typing for optimizations: > > http://dl.acm.org/citation.cfm?id=2069175 Another interesting research project into speeding up Jython using type hints:

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Paul Rubin
Steve D'Aprano writes: > On the other hand, there's Cython. Cython claims *not* to be a JIT compiler, One of the uses of "JIT compiler" these days is what's sometimes called a tracing JIT, like PyPy or LuaJIT or the Javascript flavor-of-the-week. That means it

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Steve D'Aprano
On Mon, 17 Apr 2017 04:18 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> Since it is *optional*, it is only a hint, not a fact. You can tell the >> compiler that you believe that n will be an int, but it's not guaranteed. > > The runtime could check at the entry

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Steve D'Aprano
On Sun, 16 Apr 2017 02:27 pm, Steve D'Aprano wrote: > Are you aware that optional static typing CANNOT be used for optimization? I think I've over-stated that. Considerably. In other words, I was wrong. As Steve Yegge points out, dynamic languages like Smalltalk and Lisp were, back in the

Re: Static typing [was Re: Python and the need for speed]

2017-04-17 Thread Paul Rubin
Steve D'Aprano writes: > Since it is *optional*, it is only a hint, not a fact. You can tell the > compiler that you believe that n will be an int, but it's not guaranteed. The runtime could check at the entry to the function that n is an int, and then it wouldn't

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread Steve D'Aprano
On Mon, 17 Apr 2017 05:16 am, bartc wrote: > But it was OK for Steve to 'win' the benchmark by substituting my test > code with something only vaguely related, and much simpler? Okay, you're now being obnoxious, and telling lies about me. What I said was "FOR WHAT IT'S WORTH [emphasis added],

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread Chris Angelico
On Mon, Apr 17, 2017 at 5:16 AM, bartc wrote: > On 16/04/2017 20:00, Chris Angelico wrote: >> >> On Mon, Apr 17, 2017 at 4:43 AM, bartc wrote: > > >> Sure! If all you care about is winning benchmarks, > > > The benchmarks should be about comparing things. But

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread bartc
On 16/04/2017 20:00, Chris Angelico wrote: On Mon, Apr 17, 2017 at 4:43 AM, bartc wrote: Sure! If all you care about is winning benchmarks, The benchmarks should be about comparing things. But they have to be like for like. Since this was about the effects of type

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread Chris Angelico
On Mon, Apr 17, 2017 at 4:43 AM, bartc wrote: >> >> For what it's worth, on my machine (2GB RAM and 1.2GHz CPU) I can add up >> 100 >> million ints in 14 seconds: >> >> py> with Stopwatch(): >> ... sum(range(1)) >> ... >> 49995000 >> time taken: 14.032116

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread bartc
On 16/04/2017 18:13, Steve D'Aprano wrote: On Mon, 17 Apr 2017 02:20 am, justin walters wrote: On Sun, Apr 16, 2017 at 8:46 AM, bartc wrote: What were the results with Python on your machine? Well, at first I tried to implement it with a generator. I gave up on waiting

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread Steve D'Aprano
On Mon, 17 Apr 2017 02:20 am, justin walters wrote: > On Sun, Apr 16, 2017 at 8:46 AM, bartc wrote: > >> What were the results with Python on your machine? > > > > Well, at first I tried to implement it with a generator. I gave up on > waiting for the program to complete >

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread justin walters
On Sun, Apr 16, 2017 at 8:46 AM, bartc wrote: > What were the results with Python on your machine? Well, at first I tried to implement it with a generator. I gave up on waiting for the program to complete after about 6 minutes. After using your code almost exactly I get: >>>

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread bartc
On 16/04/2017 16:00, justin walters wrote: On Sun, Apr 16, 2017 at 3:55 AM, bartc wrote: Example C of the same silly program in Python: def add(a,b): return a+b def testfn(): sum=a=b=0 for i in range(1): sum += add(a,b) a += 1 b

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread justin walters
On Sun, Apr 16, 2017 at 3:55 AM, bartc wrote: > Example C of the same silly program in Python: > > def add(a,b): > return a+b > > def testfn(): > sum=a=b=0 > for i in range(1): > sum += add(a,b) > a += 1 > b += 2 > > print

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread Chris Angelico
On Sun, Apr 16, 2017 at 8:55 PM, bartc wrote: > On 16/04/2017 05:27, Steve D'Aprano wrote: >> >> On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote: >> >>> apparently, the py-devs believe we >>> only deserve type declarations that do nothing to speed up >>> code execution (aka:

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread bartc
On 16/04/2017 05:27, Steve D'Aprano wrote: On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote: apparently, the py-devs believe we only deserve type declarations that do nothing to speed up code execution (aka: type-hints), instead of type declarations that could actually speed up the code. Go

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread alister
On Sun, 16 Apr 2017 09:48:15 +, alister wrote: > On Sun, 16 Apr 2017 14:27:28 +1000, Steve D'Aprano wrote: > >> On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote: >> >>> apparently, the py-devs believe we only deserve type declarations that >>> do nothing to speed up code execution (aka:

Re: Static typing [was Re: Python and the need for speed]

2017-04-16 Thread alister
On Sun, 16 Apr 2017 14:27:28 +1000, Steve D'Aprano wrote: > On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote: > >> apparently, the py-devs believe we only deserve type declarations that >> do nothing to speed up code execution (aka: type-hints), instead of >> type declarations that could

Static typing [was Re: Python and the need for speed]

2017-04-15 Thread Steve D'Aprano
On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote: > apparently, the py-devs believe we > only deserve type declarations that do nothing to speed up > code execution (aka: type-hints), instead of type > declarations that could actually speed up the code. Go > figure! > > I'm not a fan of forced