-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarkRunner.ns
executable file
·61 lines (57 loc) · 1.54 KB
/
BenchmarkRunner.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
Newspeak3
'Benchmarks'
class BenchmarkRunner 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 cachedPlatform = p.
|) (
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 = (
benchmarks do:
[:benchmark |
| b score |
b:: benchmark usingPlatform: cachedPlatform.
self measure: [b bench] forAtLeast: 300.
score:: measure: [b bench] forAtLeast: 2000.
(benchmark name, ': ', score) out].
)
round: n to: quantum = (
^(n // quantum) * quantum
)
) : (
)
public main: p args: argv = (
(Benchmarking usingPlatform: p) report
)
) : (
)