Last active
May 25, 2020 15:51
-
-
Save hiiamboris/4da1bccf63f4506b412977c1673c723c to your computer and use it in GitHub Desktop.
Reactivity benchmark
This file contains 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 "=== BASELINE (VIEW ONLY) ===" | |
print "" | |
print "CREATING 1000 FACES x5" | |
loop 5 [clock [do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text1]]]] | |
print "SHOWING 1000 FACES" | |
print ["p/pane:" length? p/pane "faces"] | |
clock [show p] | |
clear p/pane | |
clock [recycle] | |
print "" | |
print "=== WITH REACTIVITY ===" | |
print "" | |
print "CREATING 1000 FACES & 3000 REACTIONS x5 (A TOTAL OF 15000 REACTIONS)" | |
loop 5 [clock [do-unseen [clear p/pane loop 1000 [append p/pane make-face 'text2]]]] | |
print "SHOWING 1000 FACES & DESTROYING 12000 REACTIONS" | |
print ["p/pane:" length? p/pane "faces"] | |
print ["relations count:" (length? system/reactivity/relations) / 4] | |
clock [show p] | |
print ["relations count:" (length? system/reactivity/relations) / 4] | |
clear p/pane | |
clock [clear-reactions] | |
clock [recycle] | |
unview do-events/no-wait | |
print "" | |
print "=== ONLY REACTIVITY (NO VIEW) ===" | |
print "" | |
print "CREATING 1000 REACTORS x5" | |
b: [[][][][][]] | |
repeat i 5 [clock compose/deep [clear pick b (i) loop 1000 [append pick b (i) reactor [x: 10 y: 2 t: 0 re: copy/deep [self/t: s/s * self/x + self/y]]]]] | |
print "CREATING 15000 REACTIONS" | |
s: reactor [s: 1] | |
repeat i 5 [clock compose [foreach r pick b (i) [react/later r/re]]] | |
print ["relations count:" (length? system/reactivity/relations) / 4] | |
?? b/1/1/t ?? b/2/2/t | |
print "FIRING 15000 REACTIONS" | |
clock [s/s: 2] | |
?? b/1/1/t ?? b/2/2/t | |
print "DESTROYING 15000 REACTIONS" | |
repeat i 5 [clock compose [foreach r pick b (i) [react/unlink r/re 'all]]] | |
print ["relations count:" (length? system/reactivity/relations) / 4] | |
clock [recycle] | |
print "" | |
print "=== ONLY REACTIVITY AND OBJECTS MAINLY UNIQUE ===" | |
print "" | |
print "CREATING 1000 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 1000 [append pick b (i) make s [re: copy/deep re]]]] | |
print "CREATING 15000 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 ["relations count:" (length? system/reactivity/relations) / 4] | |
?? b/1/1/t ?? b/2/2/t | |
print "FIRING 15000 REACTIONS" | |
clock [s/t: 1] | |
?? b/1/1/t ?? b/2/2/t | |
print "DESTROYING 15000 REACTIONS" | |
repeat i 5 [clock compose [foreach r pick b (i) [react/unlink :r/re 'all]]] | |
; print ["relations count:" (length? system/reactivity/relations) / 4] | |
clock [recycle] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting better timings when all objects are mostly unique in
relations
(added test 4 to the script):(nevermind the GC caused crash)