--- a/SortColl.st Sat Apr 13 14:54:14 1996 +0200
+++ b/SortColl.st Sat Apr 13 15:29:39 1996 +0200
@@ -57,10 +57,10 @@
examples
"
- when many individual elements are to be added, it may be
- better to add them all unsorted & resort the collection completely.
+ when many elements are to be added, it may be better to add them
+ all en-bloeque instead of individually.
The reason is that for each individual #add:, the contents has to be
- moved around, to create an empty slot for the new element.
+ shifted, to create an empty slot for the new element.
timing example:
@@ -68,25 +68,23 @@
o := SortedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
]
- takes 438 ms on a DS3100 (admitted: this is a very slow machine ;-)
+ takes 1365 ms on a P5 (admitted: this is a fast machine ;-)
In contrast:
|o rnd|
o := OrderedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
].
o := o asSortedCollection
- takes 332 ms on the same machine.
- Things become more drastic with more elements; with 10000 elements,
- the times are: 15418 ms vs. 4332 ms.
+ takes 383 ms on the same machine.
If you already have a big sortedCollection at hand, adding multiple
items may be better done with #addAll:, which resorts all elements, if
@@ -97,21 +95,21 @@
o := OrderedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
].
o := o asSortedCollection.
- adding 1000 elements to it:
+ adding 1000 elements individually to it:
1000 timesRepeat:[
o add:rnd next.
].
- takes 3121 ms
+ takes 258 ms
(because the elements have to be shifted around for each added element);
- while adding them with:
+ while adding them en-bloque with:
c := OrderedCollection new.
1000 timesRepeat:[
@@ -119,7 +117,7 @@
].
o addAll:o
- taks ms
+ takes 71 ms
"
! !
@@ -716,6 +714,6 @@
!SortedCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.29 1996-04-13 12:53:36 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.30 1996-04-13 13:29:39 cg Exp $'
! !
SortedCollection initialize!
--- a/SortedCollection.st Sat Apr 13 14:54:14 1996 +0200
+++ b/SortedCollection.st Sat Apr 13 15:29:39 1996 +0200
@@ -57,10 +57,10 @@
examples
"
- when many individual elements are to be added, it may be
- better to add them all unsorted & resort the collection completely.
+ when many elements are to be added, it may be better to add them
+ all en-bloeque instead of individually.
The reason is that for each individual #add:, the contents has to be
- moved around, to create an empty slot for the new element.
+ shifted, to create an empty slot for the new element.
timing example:
@@ -68,25 +68,23 @@
o := SortedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
]
- takes 438 ms on a DS3100 (admitted: this is a very slow machine ;-)
+ takes 1365 ms on a P5 (admitted: this is a fast machine ;-)
In contrast:
|o rnd|
o := OrderedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
].
o := o asSortedCollection
- takes 332 ms on the same machine.
- Things become more drastic with more elements; with 10000 elements,
- the times are: 15418 ms vs. 4332 ms.
+ takes 383 ms on the same machine.
If you already have a big sortedCollection at hand, adding multiple
items may be better done with #addAll:, which resorts all elements, if
@@ -97,21 +95,21 @@
o := OrderedCollection new.
rnd := Random new.
- 1000 timesRepeat:[
+ 10000 timesRepeat:[
o add:rnd next.
].
o := o asSortedCollection.
- adding 1000 elements to it:
+ adding 1000 elements individually to it:
1000 timesRepeat:[
o add:rnd next.
].
- takes 3121 ms
+ takes 258 ms
(because the elements have to be shifted around for each added element);
- while adding them with:
+ while adding them en-bloque with:
c := OrderedCollection new.
1000 timesRepeat:[
@@ -119,7 +117,7 @@
].
o addAll:o
- taks ms
+ takes 71 ms
"
! !
@@ -716,6 +714,6 @@
!SortedCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.29 1996-04-13 12:53:36 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.30 1996-04-13 13:29:39 cg Exp $'
! !
SortedCollection initialize!