'From Cuis 5.0 [latest update: #3866] on 10 November 2019 at 10:52:35 am'! !BlockClosure methodsFor: 'evaluating' stamp: 'sqr - jmv 11/10/2019 10:15:20'! benchFor: aDuration "See how many times I can value in 5 seconds. I'll answer a meaningful description. [ Float pi printString ] benchFor: 100 milliSeconds. [ 80000 factorial printString ] benchFor: 1 seconds. [ 2 + 3 ] benchFor: 1.5 seconds. [ 2 + 3 ] benchFor: 1.6 seconds. [ 2 + 3. 2 + 3 ] benchFor: 1.6 seconds. [] benchFor: 2 seconds. " | totalMilliseconds startTime count run | "Same initial conditions" Smalltalk garbageCollect. "So the code doing the measurement starts jitted" Time localMillisecondClock. self value. totalMilliseconds _ self timeToRun. totalMilliseconds * 32 > aDuration totalMilliseconds ifTrue: [ totalMilliseconds / 1000 withDecimalUnitPrefixAndValue: [ :value :unitPrefixSymbol :unitPrefixName | ^ String streamContents: [ :strm | value printOn: strm fractionDigits: 2. strm space; nextPutAll: unitPrefixSymbol; nextPutAll: ' seconds per run' ]]] ifFalse: [ count _ 0. run _ true. [ (Delay forDuration: aDuration) wait. run _ false ] forkAt: Processor timingPriority - 1. startTime _ Time localMillisecondClock. [ run ] whileTrue: [ self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. self value. count _ count + 32 ]. totalMilliseconds _ Time localMillisecondClock - startTime. (count * 1000) / totalMilliseconds withDecimalUnitPrefixAndValue: [ :value :unitPrefixSymbol :unitPrefixName | ^String streamContents: [ :strm | value printOn: strm fractionDigits: 2. strm space; nextPutAll: unitPrefixSymbol; nextPutAll: ' runs per second' ]] ].! ! !BlockClosure methodsFor: 'evaluating' stamp: 'sqr 11/10/2019 10:17:21'! bench "See how many times I can value in 5 seconds. I'll answer a meaningful description. [ Float pi printString ] bench. [ 80000 factorial printString ] bench. " ^self benchFor: 5 seconds! !