Re: is python s l o o o w ? [resolved]

From: Eric Lease Morgan <emorgan_at_nyob>
Date: Mon, 18 May 2015 22:34:15 -0400
To: CODE4LIB_at_LISTSERV.ND.EDU
On May 18, 2015, at 9:23 PM, Galen Charlton <gmc_at_ESILIBRARY.COM> wrote:

>> I have two scripts, attached. They do EXACTLY the same thing
>> in almost EXACTLY the same manner, but the Python script is
>> almost 25 times slower than the Perl script:
> 
> I'm no Python expert, but I think that the difference is much more
> likely due to which JSON processor is being used.  I suspect your Perl
> environment has the JSON::XS module, which is written in C, is fast,
> and is automatically invoked (if present) by "use JSON;".
> 
> In contrast, I believe that the Python "json" library is written in
> Python itself.  I tried swapping in cjson and UltraJSON [1] in place
> of "json" in your Python script, and in both cases it ran rather
> faster.
> 
> [1] https://github.com/esnme/ultrajson


Thank you. After using the Python module ujson instead of json, the speed of my two scripts is now all but equal. Whew! —Eric
Received on Mon May 18 2015 - 22:38:03 EDT