On Tue, Feb 14, 2017 at 11:01 PM, sergio ruiz <sergio....@gmail.com> wrote:
> Hey, all.. > > I have been working on creating a REST interface using Teapot. In > learning how to handle exceptions, I have been following along with the > library example. > > One of the things i noticed was that, in the library example, they are > modeling that data a little differently than i have been.. > > to persist a list of items (and easily retrieve them), i just gave the > object an “id”, and store them on a class variable as an OrderedCollection.. > > in the library example, I see something i really like. rather than saving > an ordered collection, they save it as a dictionary. > > This dictionary goes { id -> object }.. this takes the id out of the the > object (which i really like) and makes the id generation pretty much > irrelevant.. > > my question.. is there any performance hit either way once this list grows > to tens of thousands of records? > > > I was curious, so nothing better than to experiment... myClass := Object subclass: #AA instanceVariableNames: 'id data' classVariableNames: '' package: 'AAAA'. myClass compile: 'id: i id:= i'. myClass compile: 'data: d data:= d'. N := 10 raisedTo: 7. o := OrderedCollection new. d := Dictionary new. { Time millisecondsToRun: [ 1 to: N do: [:id| o add: (AA new id: id; data: 'blahblah')]]. Time millisecondsToRun: [ 1 to: N do: [:id| d at: id put: (AA new data: 'blahblah')]]. } inspect. o := nil. d := nil. Smalltalk garbageCollect. N=5 ==> "#(5 42)" N=6 ==> "#(434 839)" N=7 ==> "#(5733 17208)" Slight modification to pre-allocate space to ignore dynamic growth cost... o := OrderedCollection new: 2 * N. d := Dictionary new: 2 * N. N=5 ==> "#(7 33)" N=6 ==> "#(411 802)" N=7 ==> "#(5892 15141)" cheers -ben