Primes by Trial Division - ParcPlace ObjectWorks Smalltalk

30 April 2017
The only difference between this and the Smalltalk/V version is the formatting of the Object and Methods declarations, as required by the FileIn task. The method definition itself is identical.
Object subclass: #Benchmark
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Benchmark'!
!Benchmark methodsFor: 'findPrimes'!
findPrimes: n
| count primes |
count := 3.
primes := OrderedCollection with: 2.
[ primes size < n ] whileTrue: [
primes detect: [ :prime | count \\ prime = 0 ] ifNone: [ primes add: count ].
count := count + 1. ].
^primes! !
"Transcript show: (Time millisecondsToRun: [
Transcript show: ((Benchmark new) findPrimes: 100) printString; cr. ] )
printString; cr."