[racket] How can I speed up this code?

From: Ray Racine (ray.racine at gmail.com)
Date: Mon Jan 14 12:23:24 EST 2013

I forced it with a

print (json.dumps (data_set))

Roughly...

Python takes 3.8 secs to parse and dump to /dev/null
Python takes 2.5 secs to parse.

On Racket, via module with -tm around a (main), I see ~40 secs.
I have a TR version of the Json parser from porting an ol' Planet lib.
 There I get ~28 secs, with ~4 secs of TR "startup" to type check.

I'm wondering if it is an ASCII vs UNICODE issue.  Looks like Python JSON
parser defaults to ASCII.


On Mon, Jan 14, 2013 at 11:53 AM, Carl Eastlund <cce at ccs.neu.edu> wrote:

> Forgive my Python-naïveté, but is Python perhaps constructing a lazy input
> stream and managing to return quickly by simply not parsing anything yet?
> Or are you able to actually run some function on the whole file, get a
> result, and still return nearly immediately while Racket takes something
> like a minute?
>
> Carl Eastlund
>
>
> On Mon, Jan 14, 2013 at 11:12 AM, J G Cho <gcho at fundingmatters.com> wrote:
>
>> Dear performance experts,
>>
>> With the news of math library in Racket and the goal of improving my
>> data analysis skill, I have started going over the examples in book
>> "Python for Data Anyalysis" by McKinney using both Python and Racket.
>> Too early to tell which is preferable for me. But I do have one
>> "problem" with Racket that I would like to resolve before going on
>> further.
>>
>> Here is the detail.
>>
>> Python:
>>
>> First I load the data
>>
>> # It looks like this at the top level;
>> # structured differently from the example in the book.
>> data_set = {
>> "meta": {},
>> "data": []
>> }
>>
>> import json
>>
>> # read in the json data downloaded from
>> #
>> https://explore.data.gov/Information-and-Communications/1-USA-gov-Short-Links/wzeq-n5pg
>> with open("usagov_bitly_data.json") as f:
>>     data_set = json.load( f )
>>
>>
>> And then I go do the usual slice and dice....
>>
>> My work flow is to edit the file and either run it inside Sublime Text
>> 2 or ipython --pylab. (v 2.7 via EPD package running on Win 7 on
>> fairly new and powerful Dell.) There is a brief pause before I see the
>> output in the screen.
>>
>>
>>
>> I run the following in DrRacket (v5.3):
>>
>> #lang racket
>>
>> (require json)
>>
>> (define data-set
>>   (call-with-input-file "usagov_bitly_data.json"
>>     (lambda (in)
>>       (read-json in))))
>>
>>
>> It takes sometime (more than a few sips of tea) where edit-run cycle
>> is not workable.
>>
>> I initially thought maybe the json library was the cause and tried
>> writing the parsed data out as .sexp and then reading that in. It did
>> not resolve the speed issue for me. I now work with a smaller subset
>> of data when I work with Racket.
>>
>> Any suggestions?
>>
>> jGc
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130114/2796426a/attachment.html>

Posted on the users mailing list.