[squeak-dev] WebClient, Json and CouchDB

Hannes Hirzel hannes.hirzel at gmail.com
Thu May 13 01:55:41 UTC 2010


Igor,

I measured it as well, see below

On 5/13/10, Igor Stasenko <siguctua at gmail.com> wrote:
> On 13 May 2010 04:02, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
>> On 5/13/10, Igor Stasenko <siguctua at gmail.com> wrote:
>>> My comment on
>>> SqS/JSON/JSON-hjh.32
>>>
>>> guys, can you give me any idea, why you replaced back the
>>>
>>> stream peek / stream next
>>>
>>> by
>>>
>>> self peek / self next
>>>
>>> removed all uses of #peekFor:
>>> and added:
>>>
>>> next
>>>       ^ self stream next
>>>
>>> peek
>>>       ^ self stream peek
>>>
>>>
>>> you're seem little concerned with speed?
>>
...
> I measured , for what it worth, on a given json, a stream peek vesion
> gives about 5% higher parsing speed:
>
> |json |
>  json := JsonObject new
> 	title: 'The title of my note card';
>  	body: 'The body test text of my note card with some Unicode test
> characters ';
> 	foo: 10;
> 	bar: #( 10 'twenty' #thirty );
> 	bar1: #( 10 'twenty' #thirty );
> 	bar2: #( 10 'twenty' #thirty );
> 	bar3: #( 10 'twenty' #thirty );
> 	bar4: #( 10 'twenty' #thirty );
> 	bar5: #( 10 20 30 22 23 24 56 34 36 34 3 634 346 'twenty' #thirty );
>       asJsonString.
>
> [ 1000 timesRepeat: [ Json readFrom: json readStream ] ] timeToRun
>
> with self peek/next:
> 1500
> 1485
>
> with stream peek/next:
>
> 1431
> 1415
>
> Also, i found that once you put more data in it, you'll get the more
> difference.
> |json |
>  json := JsonObject new
> 	bar: ((1 to: 1000) collect: [:i | i odd ifTrue: [i] ifFalse: [ 'x' ,
> i asString ] ])
>       asJsonString.
>
> [ 100 timesRepeat: [ Json readFrom: json readStream ] ] timeToRun
>
> self peek/next
> 3538
> stream peek/next
> 3294
>
> so now its 7%
>



I did a test with actually uploading data to a couchDB

|json couchDBurl |
  json := JsonObject new.
  json title: 'The title of my note card'.
  json body: 'The body test text of my note card with some Unicode
test characters ',
                   (8450 asCharacter asString, 'ä.', Character cr).
  json myTestArray: ((1 to: 1000) collect: [:i | i odd ifTrue: [i]
ifFalse: [ 'x' ,
i asString ] ]).

"Note: JsonObject behaves like a JavaScript object insofar that you
can add properties to instances without the necessity that they have
been declared as instance variables. But you might just as well use
JsonObject like a Dictionary instead as it is a subclass of
Dictionary."

"create couchDB instance"
couchDBurl := 'http://localhost:5984/notes'.

WebClient httpPut: couchDBurl
                 content: ''
                 type: 'text/plain'.

"Store first document"
[1 to: 1000 do: [ :i |
WebClient httpPut: couchDBurl, '/myNote', i printString
                 content: json asJsonString
                 type: 'text/plain'.]] timeToRun printString.

With the speedup
8979
10854

(I measured it two times)

Without the speedup
13752

So it is worth going for it.

I commited http://www.squeaksource.com/JSON/JSON-hjh.34.mcz
It contains
   stream peek
instead of
   self peek

Regards
Hannes



More information about the Squeak-dev mailing list