-----Message d'origine----- DeĀ : squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev- bounces@lists.squeakfoundation.org] De la part de Boris Gaertner
addAll: is not that bad. It is certainly better than concatenation with the #, method. The problem with repeated concatenation is that increasingly large collections are copied again and again. This is avoided both with #addAll: and with a stream (for collection that a stream can write into).
[Fakih] I compare the code you sent to me with streams. #addAll is the method with the high performance comparing to the concatenation #, (+48.57 %), and streams (+7.265%).
" use of #streams " |sets union stream| sets := OrderedCollection new. stream _ WriteStream on: {}. 1 to: 100 do: [:idx | sets add: (Set with: idx)]. Time millisecondsToRun: [ 1000 timesRepeat: [1 to: 100 do: [:idx | stream nextPutAll: (sets at: idx)]. 1 to: 100 do: [:idx | stream nextPutAll: (sets at: idx)]. ].union _ Set withAll: stream contents.].
Nevertheless if I test the following code, using streams is more performed than #addAll: (+20.2 %) as well as than concatenation #, (+78.28):
|result time stream| result _ Set new. time _ Time millisecondsToRun: [ 1 to: 10000 do: [: index | result _ result, (Set with: ('a', index asString)) ]]. Transcript cr; show: 'Concatenate Perf' ; show: time.
time _ 0. result _ Set new. time _ Time millisecondsToRun: [ 1 to: 10000 do: [: index | result addAll: (Set with: ('a', index asString)) ]]. Transcript cr; show: 'AddAll Perf' ; show: time.
time _ 0. result _ Set new. stream _ WriteStream on: {}. time _ Time millisecondsToRun: [ 1 to: 10000 do: [: index | stream nextPutAll: (Set with: ('a', index asString)) ]]. Transcript cr; show: 'Stream Perf' ; show: time ; cr ; cr.
I can't see how I can decide between #addAll and #nextPutAll in case of sets? In case of arrays to concatenate I'm convinced that streams are more efficient.
Cheers, Houssam