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

bartc bc at
Sun Apr 16 15:16:41 EDT 2017

On 16/04/2017 20:00, Chris Angelico wrote:
> On Mon, Apr 17, 2017 at 4:43 AM, bartc <bc at> 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 annotations, it would be 
interesting to see how they would affect timings in the Python example.

(I showed the affect on another language, where I got a factor of about 
100:1 between slowest and fastest by using type declarations. A bit of a 
cheat though as the typed language was really a separate one.)

  you could easily
> create a sum() that recognizes when it's given a range object. Let's
> start with a baseline. I took the code from the link Steven posted
> (and renamed Timer to Stopwatch), and:
> 4999999950000000
> time taken: 1.143872 seconds

> Ehh, too fast.

It is fast. My Python 3.4 on Intel 3.2GHz took 6 seconds. Even pypy took 
over 4 seconds.

> time taken: 0.000016 seconds
> Hey look! We win at benchmarks.

But it was OK for Steve to 'win' the benchmark by substituting my test 
code with something only vaguely related, and much simpler?


More information about the Python-list mailing list