Last active
June 19, 2020 13:23
-
-
Save hiiamboris/5241fe596dfa05ec64659d16972cbddd to your computer and use it in GitHub Desktop.
Reactivity benchmark (using faces)
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" 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 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using modified reactivity with metrics collection turned on: