-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIBenchmarkRunner.ns
executable file
·83 lines (79 loc) · 2.19 KB
/
GUIBenchmarkRunner.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Newspeak3
'Benchmarks'
class GUIBenchmarkRunner packageUsing: manifest = (
(*Infrastructure to run a set of benchmarks and gather average run times.
Copyright 2012 Google Inc.
Copyright 2013 Ryan Macnak
Licensed under the Apache License, Version 2.0 (the ''License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0*)
|
benchmarks = {
manifest ClosureDefFibonacci.
manifest ClosureFibonacci.
manifest DeltaBlue.
manifest MethodFibonacci.
manifest NLRImmediate.
manifest NLRLoop.
manifest ParserCombinators.
manifest Richards.
manifest SlotRead.
manifest SlotWrite.
manifest Splay.
}.
|) (
class Benchmarking usingPlatform: p = (|
private Stopwatch = p kernel Stopwatch.
private List = p collections List.
private Subject = p hopscotch core Subject.
private Presenter = p hopscotch core Presenter.
private HopscotchWindow = p hopscotch core HopscotchWindow.
private cachedPlatform = p.
private Smalltalk = [p squeak Smalltalk] on: Error do: [:e | nil].
|) (
class BenchmarkPresenter onSubject: s = Presenter onSubject: s () (
definition = (
^column: (benchmarks collect: [:benchmark |
initially: (label: benchmark name, ': ...') deferred: [
| b score |
b:: benchmark usingPlatform: cachedPlatform.
measure: [b bench] forAtLeast: 300.
[Smalltalk garbageCollect] on: Error do: [:e | e].
score:: measure: [b bench] forAtLeast: 2000.
label: benchmark name, ': ', score
]
])
)
) : (
)
class BenchmarkSubject = Subject onModel: nil () (
createPresenter = (
^BenchmarkPresenter onSubject: self
)
public title = (
^'Newspeak Benchmarks'
)
) : (
)
measure: block forAtLeast: milliseconds = (
| runs stopwatch elapsed score |
runs:: 0.
stopwatch:: Stopwatch new start.
[block value.
runs:: runs + 1.
elapsed:: stopwatch elapsedMilliseconds.
elapsed < milliseconds] whileTrue.
score:: (round: runs * 1000 asFloat / elapsed to: 0.1 asFloat) asFloat.
^score printString
)
public report = (
HopscotchWindow openSubject: BenchmarkSubject new.
)
round: n to: quantum = (
^(n // quantum) * quantum
)
) : (
)
public main: p args: argv = (
(Benchmarking usingPlatform: p) report
)
) : (
)