[squeak-dev] The Inbox: Kernel-ul.894.mcz

Chris Muller asqueaker at gmail.com
Thu Jan 29 02:12:41 UTC 2015


Thanks, #bench could really use some more improvements too.  I feel
comfortable to criticize bench because I wrote it.  The other day I
used it and it said, "7.124 seconds" which made me pause to consider
how the output is totally inverted when it is over 5 seconds.  One
can't simply glance at "the number," you have to read and interpret
the whole thing.  If "per second" then higher numbers are better.  If
"seconds" then lower numbers are better.  In seems inelegant, at
least, but haven't thought of something better that can still meet the
"requirements" we want bench to meet (sufficient samples, short
run-time, easy output).

Another thing.  When I see "1.5 million per second", I find myself
asking, "is that fast?"  With all of these different VM's and speeds,
I feel like I want the output to be augmented with some kind of
"relative" % measurement to the maximum speed; i.e., divide by the
speed of

  [] bench

but then Bert the other day pointed out how this is not useful for
really fast things because it ends up being slowed down by the #value
primitive (or something) so there is yet another shortcoming of bench.

And yet, one more is that we don't have a useful Magnitudinal output
for interpretation by scripts, except by parsing the string..


On Wed, Jan 28, 2015 at 1:42 PM,  <commits at source.squeak.org> wrote:
> 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