Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
Last active June 6, 2021 08:13
Show Gist options
  • Save hiiamboris/ad914d4e18c3e4400e8f0817bcda58e0 to your computer and use it in GitHub Desktop.
Save hiiamboris/ad914d4e18c3e4400e8f0817bcda58e0 to your computer and use it in GitHub Desktop.
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
; 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
]
]
@hiiamboris
Copy link
Author

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.

@pekr
Copy link

pekr commented Jun 6, 2021

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