Primes by Trial Division - DigiTalk Smalltalk/V
24 September 2016
Object subclass: #Benchmark instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' ! !Benchmark methods ! 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."