Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reactivity benchmark (using reactors)
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
num: 1000
whole-run: [
total: [
print ""
print "=== ONLY REACTIVITY (NO VIEW) ==="
print ""
print ["CREATING" num "REACTORS x5"]
b: [[][][][][]]
repeat i 5 [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 * 5 * num "REACTIONS"]
s: reactor [s: 1]
repeat i 5 [clock compose [foreach r pick b (i) [react/later r/re]]]
print-count
?? b/1/1/t ?? b/2/2/t
print ["FIRING" 3 * 5 * 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 * 5 * num "REACTIONS"]
repeat i 5 [
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 x5"]
b: [[][][][][]]
s: reactor [x: 10 y: 2 t: 0 re: [this/t: that/x + that/y + that/t / 10]]
repeat i 5 [clock compose/deep [clear pick b (i) loop num [append pick b (i) make s [re: copy/deep re]]]]
print ["CREATING" 3 * 5 * num "REACTIONS"]
prev: s
repeat i 5 [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 * 5 * 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 * 5 * num "REACTIONS"]
repeat i 5 [
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
]
]
@hiiamboris

This comment has been minimized.

Copy link
Owner Author

@hiiamboris hiiamboris commented Jun 17, 2020

Using red-08jun20-3d23acd0f --cli:


=== ONLY REACTIVITY (NO VIEW) ===

CREATING 1000 REACTORS x5
62.0 ms	[clear pick b 1 loop 1000 [append pick b 1 reactor [x: 10 y: 2 t: 0 re
63.0 ms	[clear pick b 2 loop 1000 [append pick b 2 reactor [x: 10 y: 2 t: 0 re
64.0 ms	[clear pick b 3 loop 1000 [append pick b 3 reactor [x: 10 y: 2 t: 0 re
64.0 ms	[clear pick b 4 loop 1000 [append pick b 4 reactor [x: 10 y: 2 t: 0 re
68.0 ms	[clear pick b 5 loop 1000 [append pick b 5 reactor [x: 10 y: 2 t: 0 re
CREATING 15000 REACTIONS
241 ms	[foreach r pick b 1 [react/later r/re]]
579 ms	[foreach r pick b 2 [react/later r/re]]
910 ms	[foreach r pick b 3 [react/later r/re]]
1253 ms	[foreach r pick b 4 [react/later r/re]]
1581 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
9582 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
2358 ms	[foreach r pick b 1 [react/unlink r/re 'all]]
relations count: 12000
1828 ms	[foreach r pick b 2 [react/unlink r/re 'all]]
relations count: 9000
1305 ms	[foreach r pick b 3 [react/unlink r/re 'all]]
relations count: 6000
780 ms	[foreach r pick b 4 [react/unlink r/re 'all]]
relations count: 3000
263 ms	[foreach r pick b 5 [react/unlink r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
21004 ms	[do total]
1849 ms	[recycle]

=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===

CREATING 1000 REACTORS x5
40.0 ms	[clear pick b 1 loop 1000 [append pick b 1 make s [re: copy/deep re]]]
41.0 ms	[clear pick b 2 loop 1000 [append pick b 2 make s [re: copy/deep re]]]
42.0 ms	[clear pick b 3 loop 1000 [append pick b 3 make s [re: copy/deep re]]]
63.0 ms	[clear pick b 4 loop 1000 [append pick b 4 make s [re: copy/deep re]]]
67.0 ms	[clear pick b 5 loop 1000 [append pick b 5 make s [re: copy/deep re]]]
CREATING 15000 REACTIONS
240 ms	[foreach r pick b 1 [react/link/later r/re: func [this that] r/re [r p
556 ms	[foreach r pick b 2 [react/link/later r/re: func [this that] r/re [r p
862 ms	[foreach r pick b 3 [react/link/later r/re: func [this that] r/re [r p
1196 ms	[foreach r pick b 4 [react/link/later r/re: func [this that] r/re [r p
1505 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
12876 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
2362 ms	[foreach r pick b 1 [react/unlink :r/re 'all]]
relations count: 12000
1833 ms	[foreach r pick b 2 [react/unlink :r/re 'all]]
relations count: 9000
1315 ms	[foreach r pick b 3 [react/unlink :r/re 'all]]
relations count: 6000
789 ms	[foreach r pick b 4 [react/unlink :r/re 'all]]
relations count: 3000
275 ms	[foreach r pick b 5 [react/unlink :r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
24065 ms	[do total]
relations count: 0
46919 ms	[do whole-run]
@hiiamboris

This comment has been minimized.

Copy link
Owner Author

@hiiamboris hiiamboris commented Jun 17, 2020

Using modified reactivity:


=== ONLY REACTIVITY (NO VIEW) ===

CREATING 1000 REACTORS x5
72.0 ms	[clear pick b 1 loop 1000 [append pick b 1 reactor [x: 10 y: 2 t: 0 re
73.0 ms	[clear pick b 2 loop 1000 [append pick b 2 reactor [x: 10 y: 2 t: 0 re
74.0 ms	[clear pick b 3 loop 1000 [append pick b 3 reactor [x: 10 y: 2 t: 0 re
73.0 ms	[clear pick b 4 loop 1000 [append pick b 4 reactor [x: 10 y: 2 t: 0 re
76.0 ms	[clear pick b 5 loop 1000 [append pick b 5 reactor [x: 10 y: 2 t: 0 re
CREATING 15000 REACTIONS
176 ms	[foreach r pick b 1 [react/later r/re]]
352 ms	[foreach r pick b 2 [react/later r/re]]
528 ms	[foreach r pick b 3 [react/later r/re]]
706 ms	[foreach r pick b 4 [react/later r/re]]
880 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
463 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
158 ms	[foreach r pick b 1 [react/unlink r/re 'all]]
relations count: 12000
158 ms	[foreach r pick b 2 [react/unlink r/re 'all]]
relations count: 9000
151 ms	[foreach r pick b 3 [react/unlink r/re 'all]]
relations count: 6000
99.0 ms	[foreach r pick b 4 [react/unlink r/re 'all]]
relations count: 3000
43.0 ms	[foreach r pick b 5 [react/unlink r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
4121 ms	[do total]
1623 ms	[recycle]

=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===

CREATING 1000 REACTORS x5
47.0 ms	[clear pick b 1 loop 1000 [append pick b 1 make s [re: copy/deep re]]]
48.0 ms	[clear pick b 2 loop 1000 [append pick b 2 make s [re: copy/deep re]]]
49.0 ms	[clear pick b 3 loop 1000 [append pick b 3 make s [re: copy/deep re]]]
66.0 ms	[clear pick b 4 loop 1000 [append pick b 4 make s [re: copy/deep re]]]
74.0 ms	[clear pick b 5 loop 1000 [append pick b 5 make s [re: copy/deep re]]]
CREATING 15000 REACTIONS
178 ms	[foreach r pick b 1 [react/link/later r/re: func [this that] r/re [r p
184 ms	[foreach r pick b 2 [react/link/later r/re: func [this that] r/re [r p
189 ms	[foreach r pick b 3 [react/link/later r/re: func [this that] r/re [r p
204 ms	[foreach r pick b 4 [react/link/later r/re: func [this that] r/re [r p
196 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
2492 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
47.0 ms	[foreach r pick b 1 [react/unlink :r/re 'all]]
relations count: 12000
45.0 ms	[foreach r pick b 2 [react/unlink :r/re 'all]]
relations count: 9000
44.0 ms	[foreach r pick b 3 [react/unlink :r/re 'all]]
relations count: 6000
43.0 ms	[foreach r pick b 4 [react/unlink :r/re 'all]]
relations count: 3000
42.0 ms	[foreach r pick b 5 [react/unlink :r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
4016 ms	[do total]
relations count: 0
9760 ms	[do whole-run]
@hiiamboris

This comment has been minimized.

Copy link
Owner Author

@hiiamboris hiiamboris commented Jun 17, 2020

Using modified reactivity with metrics collection turned on:


=== ONLY REACTIVITY (NO VIEW) ===

CREATING 1000 REACTORS x5
98.0 ms	[clear pick b 1 loop 1000 [append pick b 1 reactor [x: 10 y: 2 t: 0 re
100 ms	[clear pick b 2 loop 1000 [append pick b 2 reactor [x: 10 y: 2 t: 0 re
101 ms	[clear pick b 3 loop 1000 [append pick b 3 reactor [x: 10 y: 2 t: 0 re
99.0 ms	[clear pick b 4 loop 1000 [append pick b 4 reactor [x: 10 y: 2 t: 0 re
103 ms	[clear pick b 5 loop 1000 [append pick b 5 reactor [x: 10 y: 2 t: 0 re
CREATING 15000 REACTIONS
222 ms	[foreach r pick b 1 [react/later r/re]]
404 ms	[foreach r pick b 2 [react/later r/re]]
579 ms	[foreach r pick b 3 [react/later r/re]]
761 ms	[foreach r pick b 4 [react/later r/re]]
936 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
979 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
164 ms	[foreach r pick b 1 [react/unlink r/re 'all]]
relations count: 12000
165 ms	[foreach r pick b 2 [react/unlink r/re 'all]]
relations count: 9000
157 ms	[foreach r pick b 3 [react/unlink r/re 'all]]
relations count: 6000
106 ms	[foreach r pick b 4 [react/unlink r/re 'all]]
relations count: 3000
47.0 ms	[foreach r pick b 5 [react/unlink r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
5066 ms	[do total]
4342 ms	[recycle]

=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===

CREATING 1000 REACTORS x5
53.0 ms	[clear pick b 1 loop 1000 [append pick b 1 make s [re: copy/deep re]]]
54.0 ms	[clear pick b 2 loop 1000 [append pick b 2 make s [re: copy/deep re]]]
58.0 ms	[clear pick b 3 loop 1000 [append pick b 3 make s [re: copy/deep re]]]
78.0 ms	[clear pick b 4 loop 1000 [append pick b 4 make s [re: copy/deep re]]]
86.0 ms	[clear pick b 5 loop 1000 [append pick b 5 make s [re: copy/deep re]]]
CREATING 15000 REACTIONS
237 ms	[foreach r pick b 1 [react/link/later r/re: func [this that] r/re [r p
240 ms	[foreach r pick b 2 [react/link/later r/re: func [this that] r/re [r p
244 ms	[foreach r pick b 3 [react/link/later r/re: func [this that] r/re [r p
265 ms	[foreach r pick b 4 [react/link/later r/re: func [this that] r/re [r p
260 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
3224 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
52.0 ms	[foreach r pick b 1 [react/unlink :r/re 'all]]
relations count: 12000
53.0 ms	[foreach r pick b 2 [react/unlink :r/re 'all]]
relations count: 9000
49.0 ms	[foreach r pick b 3 [react/unlink :r/re 'all]]
relations count: 6000
47.0 ms	[foreach r pick b 4 [react/unlink :r/re 'all]]
relations count: 3000
47.0 ms	[foreach r pick b 5 [react/unlink :r/re 'all]]
relations count: 0
0.0 μs	[clear-reactions]
5116 ms	[do total]
relations count: 0
14525 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:09.55855
    adding relations:    0:00:03.80822 (preparations: 0:00:00.901052 )
    removing relations:  0:00:00.843048
    dispatching:         0:00:04.90728
    longest queue flush: 0:00:00.0020001
Peak values:
    maximum queue size:  5000
    maximum index size:  5000
    biggest relation:    2 reactors
    most used reactor:   5000 relations
@greggirwin

This comment has been minimized.

Copy link

@greggirwin greggirwin commented Jun 17, 2020

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.

@greggirwin

This comment has been minimized.

Copy link

@greggirwin greggirwin commented Jun 17, 2020

The speedup is impressive. 👍

@hiiamboris

This comment has been minimized.

Copy link
Owner Author

@hiiamboris hiiamboris commented Jun 19, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment