[squeak-dev] The Inbox: Kernel-ul.894.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Jan 28 19:42:09 UTC 2015
Levente Uzonyi uploaded a new version of Kernel to project The Inbox:
http://source.squeak.org/inbox/Kernel-ul.894.mcz
==================== Summary ====================
Name: Kernel-ul.894
Author: ul
Time: 28 January 2015, 8:41:20.772 pm
UUID: fedfafb3-de95-42eb-bb32-609455c6b1b9
Ancestors: Kernel-ul.893
Avoid the frequent time checks, and the clock rollover bug in BlockClosure >> #bench.
Introduce #bench:, a variant of #bench, which takes the duration of the benchmark as parameter. E.g.:
[ 10 factorial ] bench: 0.1 seconds.
[ 100 factorial ] bench: 10 seconds.
=============== Diff against Kernel-ul.893 ===============
Item was changed:
----- Method: BlockClosure>>bench (in category 'evaluating') -----
bench
"See how many times I can value in 5 seconds. I'll answer a meaningful description."
+ ^self bench: 5 seconds!
- | startTime endTime count roundTo3Digits |
- roundTo3Digits := [:num |
- | rounded lowDigit |
- rounded := (num * 1000) rounded. "round to 1/1000"
- lowDigit := (rounded numberOfDigitsInBase: 10) - 3. "keep only first 3 digits"
- rounded := rounded roundTo:(10 raisedTo: lowDigit).
- (lowDigit >= 3 or: [rounded \\ 1000 = 0]) "display fractional part only when needed"
- ifTrue: [(rounded // 1000) asStringWithCommas]
- ifFalse: [(rounded / 1000.0) printString]].
- count := 0.
- endTime := Time millisecondClockValue + 5000.
- startTime := Time millisecondClockValue.
- [ Time millisecondClockValue > endTime ] whileFalse: [ self value. count := count + 1 ].
- endTime := Time millisecondClockValue.
- ^count = 1
- ifTrue: [ (roundTo3Digits value: (endTime - startTime) / 1000) , ' seconds.' ]
- ifFalse:
- [ (roundTo3Digits value: (count * 1000) / (endTime - startTime)) , ' per second.' ]!
Item was added:
+ ----- Method: BlockClosure>>bench: (in category 'evaluating') -----
+ bench: aDuration
+ "See how many times I can value within the given duration. I'll answer a meaningful description."
+
+ | startTime elapsedTime count roundTo3Digits |
+ roundTo3Digits := [:num |
+ | rounded lowDigit |
+ rounded := (num * 1000) rounded. "round to 1/1000"
+ lowDigit := (rounded numberOfDigitsInBase: 10) - 3. "keep only first 3 digits"
+ rounded := rounded roundTo:(10 raisedTo: lowDigit).
+ (lowDigit >= 3 or: [rounded \\ 1000 = 0]) "display fractional part only when needed"
+ ifTrue: [(rounded // 1000) asStringWithCommas]
+ ifFalse: [(rounded / 1000.0) printString]].
+ count := 0.
+ [
+ startTime := Time millisecondClockValue.
+ [
+ self value.
+ count := count + 1 ] repeat ]
+ valueWithin: aDuration
+ onTimeout: [ elapsedTime := Time millisecondsSince: startTime ].
+ ^count = 1
+ ifTrue: [ (roundTo3Digits value: elapsedTime / 1000) , ' seconds.' ]
+ ifFalse:
+ [ (roundTo3Digits value: (count * 1000) / elapsedTime) , ' per second.' ]!
More information about the Squeak-dev
mailing list
|