Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reactivity benchmark (using faces)
Red [title: "reactivity benchmark" needs: view] ;) run as `red --cli ...` to eliminate GUI console influence!
do https://gitlab.com/hiiamboris/red-mezz-warehouse/-/raw/master/clock.red
do-unseen: function [code [block!]] [
old: system/view/auto-sync?
system/view/auto-sync?: no
do code
system/view/auto-sync?: old
]
extend system/view/VID/styles [
text1: [
template: [type: 'text size: 80x25]
init: [ ;) baseline: creates a function, executes, doesn't use it
f: func [f _] [
[f/data f/offset f/size]
f/text: "text"
]
f face face
]
]
text2: [
template: [type: 'text size: 80x25]
init: [
react/link func [f _] [
[f/data f/offset f/size] ;) define reactive sources (3 sources = 3 reactions)
f/text: "text"
] [face face]
]
]
]
view/no-wait [p: panel []]
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 "=== BASELINE (VIEW ONLY) ==="
print ""
print ["CREATING" num "FACES x5"]
loop 5 [clock [do-unseen [clear p/pane loop num [append p/pane make-face 'text1]]]]
print ["p/pane:" length? p/pane "faces"]
print ["SHOWING" num "FACES"]
clock [show p]
clear p/pane
]
clock [do total]
clock [recycle]
total: [
print ""
print "=== WITH REACTIVITY ==="
print ""
print ["CREATING" num "FACES &" num * 3 "REACTIONS x5 (A TOTAL OF" 3 * 5 * num "REACTIONS)"]
loop 5 [clock [do-unseen [clear p/pane loop num [append p/pane make-face 'text2]]]]
print ["p/pane:" length? p/pane "faces"]
print-count
print ["SHOWING" num "FACES & DESTROYING" 3 * 4 * num "REACTIONS"]
clock [show p]
print-count
clear p/pane
clock [clear-reactions]
]
clock [do total]
clock [recycle]
unview do-events/no-wait
]
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:

=== BASELINE (VIEW ONLY) ===

CREATING 1000 FACES x5
203 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
201 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
202 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
201 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
203 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
p/pane: 1000 faces
SHOWING 1000 FACES
2929 ms	[show p]
4704 ms	[do total]
4396 ms	[recycle]

=== WITH REACTIVITY ===

CREATING 1000 FACES & 3000 REACTIONS x5 (A TOTAL OF 15000 REACTIONS)
665 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
1341 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
2008 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
2679 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
3347 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
p/pane: 1000 faces
relations count: 15000
SHOWING 1000 FACES & DESTROYING 12000 REACTIONS
41815 ms	[show p]
relations count: 3000
0.0 μs	[clear-reactions]
54163 ms	[do total]
8913 ms	[recycle]
72183 ms	[do whole-run]
@hiiamboris

This comment has been minimized.

Copy link
Owner Author

@hiiamboris hiiamboris commented Jun 17, 2020

Using modified reactivity:

=== BASELINE (VIEW ONLY) ===

CREATING 1000 FACES x5
211 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
207 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
205 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
210 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
210 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
p/pane: 1000 faces
SHOWING 1000 FACES
2947 ms	[show p]
4752 ms	[do total]
4749 ms	[recycle]

=== WITH REACTIVITY ===

CREATING 1000 FACES & 3000 REACTIONS x5 (A TOTAL OF 15000 REACTIONS)
291 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
292 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
295 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
295 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
291 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
p/pane: 1000 faces
relations count: 15000
SHOWING 1000 FACES & DESTROYING 12000 REACTIONS
2994 ms	[show p]
relations count: 3000
0.0 μs	[clear-reactions]
5260 ms	[do total]
5919 ms	[recycle]
20685 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:

=== BASELINE (VIEW ONLY) ===

CREATING 1000 FACES x5
221 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
222 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
216 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
221 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
222 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]
p/pane: 1000 faces
SHOWING 1000 FACES
3050 ms	[show p]
4900 ms	[do total]
4880 ms	[recycle]

=== WITH REACTIVITY ===

CREATING 1000 FACES & 3000 REACTIONS x5 (A TOTAL OF 15000 REACTIONS)
365 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
366 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
368 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
366 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
367 ms	[do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]
p/pane: 1000 faces
relations count: 15000
SHOWING 1000 FACES & DESTROYING 12000 REACTIONS
3134 ms	[show p]
relations count: 3000
0.0 μs	[clear-reactions]
5758 ms	[do total]
7369 ms	[recycle]
22913 ms	[do whole-run]

***** REACTIVITY METRICS REPORT *****
Metrics collection enabled?: true
Statistical counts:
    events triggered:    0
    reactions fired:     5000 (immediately: 5000 , queued: 0 )
    reactions skipped:   0
Time spent in reactions: 0:00:00
Time spent in reactivity:
    total:               0:00:00.69704
    adding relations:    0:00:00.582034 (preparations: 0:00:00.33002 )
    removing relations:  0:00:00.0770039
    dispatching:         0:00:00.0380024
    longest queue flush: 0:00:00
Peak values:
    maximum queue size:  0
    maximum index size:  5000
    biggest relation:    1 reactors
    most used reactor:   3 relations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment