-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bench.st
51 lines (40 loc) · 1.14 KB
/
Bench.st
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
Integer extend [
tinyBenchmarks [
<category: 'benchmarks'>
| t1 t2 r n1 n2 |
n1 := 1 bitShift: self.
[ t1 := Time millisecondsToRun: [ n1 benchmark ].
t1 < 5000 ] whileTrue:[ n1 := n1 * 2 ].
n2 := 24 + self.
[ t2 := Time millisecondsToRun: [r := n2 benchFib].
t2 < 5000] whileTrue:[ n2 := n2 + 1 ].
^((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ', ((r * 1000) // t2) printString, ' sends/sec'
]
benchFib [
<category: 'benchmarks'>
^ self < 2
ifTrue: [ 1 ]
ifFalse: [ (self - 1) benchFib + (self - 2) benchFib + 1 ]
]
benchmark [
<category: 'benchmarks'>
| size flags prime k count |
size := 8190.
flags := Array new: size.
self timesRepeat: [
count := 0.
flags atAllPut: true.
1 to: size do:
[:i | (flags at: i) ifTrue:
[prime := i + 1.
k := i + prime.
[k <= size] whileTrue:
[flags at: k put: false.
k := k + prime].
count := count + 1]]].
^ count
]
]
Eval [
Transcript showCr: 12 tinyBenchmarks
]