The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

BartC bc at freeuk.com
Thu Mar 24 12:12:33 EDT 2016


On 24/03/2016 15:30, Ned Batchelder wrote:
> On Thursday, March 24, 2016 at 9:51:11 AM UTC-4, Steven D'Aprano wrote:
>> You know what is missing from this conversation?
>>
>> For one of Bart's critics to actually show faster code.
>>
>> There's plenty of people telling him off for writing unpythonic and slow
>> code, but I haven't seen anyone actually demonstrating that Python is
>> faster than his results show.
>
> As I mentioned before, I'm happy to explain the fuller Python way to
> write code, but I don't think Bart wants to learn it, because he is
> focused on a different goal than, "write real Python code the best
> possible way."
>
> Here, for example, is a real lexer for JavaScript that I wrote:
> https://bitbucket.org/ned/jslex/src
>

Thanks for that.

I don't have any JS to throw at it, but it seems happy with any bits of 
source code or even just text.

Using your short driver program (with the prints commented out), and 
tested with 'bible.txt' as input (ie. mostly English words), then your 
JS lexer was roughly half the speed of the Python version I linked to 
last week (with the if-elif chains and working with strings).

Both tested with 2.7.x. Using PyPy speeded both versions up about 3 times.

Your code however is more beautiful than mine...

 > It makes heavy use of regexes to go fast.  I don't have benchmarks
 > against other implementations unfortunately.

(A rough lines-per-second figure would give a general idea.)

-- 
Bartc




More information about the Python-list mailing list