If you did not profile your code you may have 40-50% speed up waiting for you.
We create an expression and use [ expression ] timeToRun
[ 1000 factorial ] timeToRun
Is select:
, then collect:
slower than select:thenCollect:
?
| coll |
coll := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection.
[ 1000000 timesRepeat: [
(coll select: [ :each | each > 5]) collect: [ :i | i * i ]]
] timeToRun
> "0:00:00:00.517"
| coll |
coll := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection.
[ 1000000 timesRepeat: [
coll
select: [ :each | each > 5]
thenCollect: [ :i | i * i ]]
] timeToRun
> "0:00:00:00.362"
[ 1000 factorial ] bench
> '610.234 per second'
The higher the better!
[ 1234 factorial ] benchFor: 2 seconds
TimeProfiler
: a sampling-based code profilerTimeProfiler
spyOn: [ 20 timesRepeat: [
Transcript show: 1000 factorial printString ] ]
[ anExpression ] timeToRun
[ anExpression ] bench
TimeProfiler spyOn: [ anExpression ]
/