Primes by Trial Division - Smalltalk-80

8 October 2017
Smalltalk-80 uses a non-standard character set, which includes arrows for assignment and method return.
Object subclass: #Benchmark
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Benchmark'!
!Benchmark methodsFor: 'findPrimes' !
findPrimes: n
    | count primes prime |
    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."