Last active
June 6, 2021 08:13
-
-
Save hiiamboris/ad914d4e18c3e4400e8f0817bcda58e0 to your computer and use it in GitHub Desktop.
Reactivity benchmark (using reactors)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [title: "reactivity benchmark"] ;) run as `red --cli ...` to eliminate GUI console influence! | |
do https://gitlab.com/hiiamboris/red-mezz-warehouse/-/raw/master/clock.red | |
recycle/off | |
print-count: does [ | |
attempt [print ["relations count:" (length? system/reactivity/relations) / 4]] | |
attempt [print ["relations count:" system/reactivity/relations-count]] | |
] | |
attempt [system/reactivity/metrics?: yes] ;) uncomment to obtain metrics | |
; attempt [system/reactivity/debug?: yes] | |
num: 1000 rep: 5 | |
whole-run: [ | |
total: [ | |
print "" | |
print "=== ONLY REACTIVITY (NO VIEW) ===" | |
print "" | |
print ["CREATING" num "REACTORS x" rep] | |
b: [[][][][][]] | |
repeat i rep [clock compose/deep [clear pick b (i) loop num [append pick b (i) reactor [x: 10 y: 2 t: 0 re: copy/deep [self/t: s/s * self/x + self/y]]]]] | |
print ["CREATING" 3 * rep * num "REACTIONS"] | |
s: reactor [s: 1] | |
repeat i rep [clock compose [foreach r pick b (i) [react/later r/re]]] | |
print-count | |
?? b/1/1/t ?? b/2/2/t | |
print ["FIRING" 3 * rep * num "REACTIONS (SINGLE SOURCE) x5"] | |
clock [s/s: 2 s/s: 3 s/s: 4 s/s: 5 s/s: 6] | |
?? b/1/1/t ?? b/2/2/t | |
print ["DESTROYING" 3 * rep * num "REACTIONS"] | |
repeat i rep [ | |
clock compose [foreach r pick b (i) [react/unlink r/re 'all]] | |
print-count | |
] | |
clock [clear-reactions] | |
] | |
clock [do total] | |
clock [recycle] | |
total: [ | |
print "" | |
print "=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===" | |
print "" | |
print ["CREATING" num "REACTORS x" rep] | |
b: [[][][][][]] | |
s: reactor [x: 10 y: 2 t: 0 re: [this/t: that/x + that/y + that/t / 10]] | |
repeat i rep [clock compose/deep [clear pick b (i) loop num [append pick b (i) make s [re: copy/deep re]]]] | |
print ["CREATING" 3 * rep * num "REACTIONS"] | |
prev: s | |
repeat i rep [clock compose [foreach r pick b (i) [react/link/later r/re: func [this that] r/re [r prev] prev: r]]] | |
print-count | |
?? b/1/1/t ?? b/2/2/t | |
print ["FIRING" 3 * rep * num "REACTIONS (SINGLE CHAIN) x5"] | |
clock [s/t: 1 s/t: 2 s/t: 3 s/t: 4 s/t: 5] | |
?? b/1/1/t ?? b/2/2/t | |
print ["DESTROYING" 3 * rep * num "REACTIONS"] | |
repeat i rep [ | |
clock compose [foreach r pick b (i) [react/unlink :r/re 'all]] | |
print-count | |
] | |
clock [clear-reactions] | |
] | |
clock [do total] | |
; clock [recycle] ;@@ CRASHES - #4514 | |
print-count | |
] | |
clock [do whole-run] | |
attempt [ | |
if system/reactivity/metrics? [ | |
system/reactivity/metrics/show | |
] | |
] |
Using modified reactivity:
=== ONLY REACTIVITY (NO VIEW) ===
CREATING 1000 REACTORS x 5
18.0 ms [clear pick b 1 loop num [append pick b 1 reactor [x: 10 y: 2 t: 0 re:
15.5 ms [clear pick b 2 loop num [append pick b 2 reactor [x: 10 y: 2 t: 0 re:
16.9 ms [clear pick b 3 loop num [append pick b 3 reactor [x: 10 y: 2 t: 0 re:
18.0 ms [clear pick b 4 loop num [append pick b 4 reactor [x: 10 y: 2 t: 0 re:
19.0 ms [clear pick b 5 loop num [append pick b 5 reactor [x: 10 y: 2 t: 0 re:
CREATING 15000 REACTIONS
129 ms [foreach r pick b 1 [react/later r/re]]
247 ms [foreach r pick b 2 [react/later r/re]]
321 ms [foreach r pick b 3 [react/later r/re]]
414 ms [foreach r pick b 4 [react/later r/re]]
484 ms [foreach r pick b 5 [react/later r/re]]
relations count: 15000
b/1/1/t: 0
b/2/2/t: 0
FIRING 15000 REACTIONS (SINGLE SOURCE) x5
180 ms [s/s: 2 s/s: 3 s/s: 4 s/s: 5 s/s: 6]
b/1/1/t: 62
b/2/2/t: 62
DESTROYING 15000 REACTIONS
144 ms [foreach r pick b 1 [react/unlink r/re 'all]]
relations count: 12000
167 ms [foreach r pick b 2 [react/unlink r/re 'all]]
relations count: 9000
194 ms [foreach r pick b 3 [react/unlink r/re 'all]]
relations count: 6000
131 ms [foreach r pick b 4 [react/unlink r/re 'all]]
relations count: 3000
53.1 ms [foreach r pick b 5 [react/unlink r/re 'all]]
relations count: 0
0.0 μs [clear-reactions]
2589 ms [do total]
49.0 ms [recycle]
=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===
CREATING 1000 REACTORS x 5
11.0 ms [clear pick b 1 loop num [append pick b 1 make s [re: copy/deep re]]]
10.0 ms [clear pick b 2 loop num [append pick b 2 make s [re: copy/deep re]]]
12.0 ms [clear pick b 3 loop num [append pick b 3 make s [re: copy/deep re]]]
17.9 ms [clear pick b 4 loop num [append pick b 4 make s [re: copy/deep re]]]
20.5 ms [clear pick b 5 loop num [append pick b 5 make s [re: copy/deep re]]]
CREATING 15000 REACTIONS
102 ms [foreach r pick b 1 [react/link/later r/re: func [this that] r/re [r p
116 ms [foreach r pick b 2 [react/link/later r/re: func [this that] r/re [r p
119 ms [foreach r pick b 3 [react/link/later r/re: func [this that] r/re [r p
121 ms [foreach r pick b 4 [react/link/later r/re: func [this that] r/re [r p
128 ms [foreach r pick b 5 [react/link/later r/re: func [this that] r/re [r p
relations count: 15000
b/1/1/t: 0
b/2/2/t: 0
FIRING 15000 REACTIONS (SINGLE CHAIN) x5
1282 ms [s/t: 1 s/t: 2 s/t: 3 s/t: 4 s/t: 5]
b/1/1/t: 1.7
b/2/2/t: 1.3333333333333335
DESTROYING 15000 REACTIONS
42.1 ms [foreach r pick b 1 [react/unlink :r/re 'all]]
relations count: 12000
35.1 ms [foreach r pick b 2 [react/unlink :r/re 'all]]
relations count: 9000
35.3 ms [foreach r pick b 3 [react/unlink :r/re 'all]]
relations count: 6000
31.0 ms [foreach r pick b 4 [react/unlink :r/re 'all]]
relations count: 3000
31.9 ms [foreach r pick b 5 [react/unlink :r/re 'all]]
relations count: 0
0.0 μs [clear-reactions]
2159 ms [do total]
relations count: 0
4798 ms [do whole-run]
Using modified reactivity with metrics collection turned on:
=== ONLY REACTIVITY (NO VIEW) ===
CREATING 1000 REACTORS x 5
20.9 ms [clear pick b 1 loop num [append pick b 1 reactor [x: 10 y: 2 t: 0 re:
19.0 ms [clear pick b 2 loop num [append pick b 2 reactor [x: 10 y: 2 t: 0 re:
20.4 ms [clear pick b 3 loop num [append pick b 3 reactor [x: 10 y: 2 t: 0 re:
19.5 ms [clear pick b 4 loop num [append pick b 4 reactor [x: 10 y: 2 t: 0 re:
23.0 ms [clear pick b 5 loop num [append pick b 5 reactor [x: 10 y: 2 t: 0 re:
CREATING 15000 REACTIONS
181 ms [foreach r pick b 1 [react/later r/re]]
294 ms [foreach r pick b 2 [react/later r/re]]
425 ms [foreach r pick b 3 [react/later r/re]]
490 ms [foreach r pick b 4 [react/later r/re]]
523 ms [foreach r pick b 5 [react/later r/re]]
relations count: 15000
b/1/1/t: 0
b/2/2/t: 0
FIRING 15000 REACTIONS (SINGLE SOURCE) x5
469 ms [s/s: 2 s/s: 3 s/s: 4 s/s: 5 s/s: 6]
b/1/1/t: 62
b/2/2/t: 62
DESTROYING 15000 REACTIONS
136 ms [foreach r pick b 1 [react/unlink r/re 'all]]
relations count: 12000
168 ms [foreach r pick b 2 [react/unlink r/re 'all]]
relations count: 9000
193 ms [foreach r pick b 3 [react/unlink r/re 'all]]
relations count: 6000
130 ms [foreach r pick b 4 [react/unlink r/re 'all]]
relations count: 3000
56.0 ms [foreach r pick b 5 [react/unlink r/re 'all]]
relations count: 0
0.0 μs [clear-reactions]
3195 ms [do total]
297 ms [recycle]
=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===
CREATING 1000 REACTORS x 5
11.0 ms [clear pick b 1 loop num [append pick b 1 make s [re: copy/deep re]]]
11.1 ms [clear pick b 2 loop num [append pick b 2 make s [re: copy/deep re]]]
11.8 ms [clear pick b 3 loop num [append pick b 3 make s [re: copy/deep re]]]
18.1 ms [clear pick b 4 loop num [append pick b 4 make s [re: copy/deep re]]]
22.0 ms [clear pick b 5 loop num [append pick b 5 make s [re: copy/deep re]]]
CREATING 15000 REACTIONS
165 ms [foreach r pick b 1 [react/link/later r/re: func [this that] r/re [r p
172 ms [foreach r pick b 2 [react/link/later r/re: func [this that] r/re [r p
170 ms [foreach r pick b 3 [react/link/later r/re: func [this that] r/re [r p
178 ms [foreach r pick b 4 [react/link/later r/re: func [this that] r/re [r p
178 ms [foreach r pick b 5 [react/link/later r/re: func [this that] r/re [r p
relations count: 15000
b/1/1/t: 0
b/2/2/t: 0
FIRING 15000 REACTIONS (SINGLE CHAIN) x5
1776 ms [s/t: 1 s/t: 2 s/t: 3 s/t: 4 s/t: 5]
b/1/1/t: 1.7
b/2/2/t: 1.3333333333333335
DESTROYING 15000 REACTIONS
45.2 ms [foreach r pick b 1 [react/unlink :r/re 'all]]
relations count: 12000
50.2 ms [foreach r pick b 2 [react/unlink :r/re 'all]]
relations count: 9000
45.9 ms [foreach r pick b 3 [react/unlink :r/re 'all]]
relations count: 6000
47.6 ms [foreach r pick b 4 [react/unlink :r/re 'all]]
relations count: 3000
40.1 ms [foreach r pick b 5 [react/unlink :r/re 'all]]
relations count: 0
0.0 μs [clear-reactions]
2991 ms [do total]
relations count: 0
6483 ms [do whole-run]
***** REACTIVITY METRICS REPORT *****
Metrics collection enabled?: true
Statistical counts:
events triggered: 80015
reactions fired: 50000 (immediately: 25005 , queued: 24995 )
reactions skipped: 0
Time spent in reactions: 0:00:00
Time spent in reactivity:
total: 0:00:06.43748
adding relations: 0:00:02.62727 (preparations: 0:00:00.731315 )
removing relations: 0:00:00.876593
dispatching: 0:00:02.93362
longest queue flush: 0:00:00.0042213
Peak values:
max queue size: 5000
max reactors count: 5001
max reactions count: 5000
biggest relation: 2 reactors
biggest reactor: 5000 relations
I love numbers. I love even more when the loop counts are broken out, to play at various sizes. Something to think about for a profiling dialect.
The speedup is impressive. 👍
when the loop counts are broken out, to play at various sizes
:D Yeah I should have overcome my laziness. I'll do that and update the script.
This is perfect. Will this improvement become part of Red? :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
red-12may21
: