Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
Created May 21, 2018 23:33
Show Gist options
  • Save nedzadarek/d08b14829b1a8260e1eebb5e45c374cc to your computer and use it in GitHub Desktop.
Save nedzadarek/d08b14829b1a8260e1eebb5e45c374cc to your computer and use it in GitHub Desktop.
from tuple to block
Red [
author: "Nędza Darek"
license: {
- use/modify everywhere
- point to this gist
}
url: https://gitter.im/red/help?at=5b0301c3d245fe2eb7ca406c
info: {
Code that I used:
`profile`: https://gist.github.com/greggirwin/908d44dc069ed84cf69f053e1308390d
`collect`'s code: https://gitter.im/red/help?at=5b0302fab84be71db924898a
}
]
repetitions: 50'000
arr: copy [] repeat n (3 + random 9) [append arr random 42]
p: to-tuple arr
tuples-copy-compose: [(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8) (p/9) (p/10) (p/11) (p/12)]
tuples-copy-reduce: [p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8 p/9 p/10 p/11 p/12]
tuples: [
'dummy
'dummy
[(p/1) (p/2) (p/3)]
[(p/1) (p/2) (p/3) (p/4)]
[(p/1) (p/2) (p/3) (p/4) (p/5)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8) (p/9)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8) (p/9) (p/10)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8) (p/9) (p/10) (p/11)]
[(p/1) (p/2) (p/3) (p/4) (p/5) (p/6) (p/7) (p/8) (p/9) (p/10) (p/11) (p/12)]
]
tuples-reduce: [
'dummy
'dummy
[p/1 p/2 p/3]
[p/1 p/2 p/3 p/4 ]
[p/1 p/2 p/3 p/4 p/5]
[p/1 p/2 p/3 p/4 p/5 p/6]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8 p/9]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8 p/9 p/10]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8 p/9 p/10 p/11]
[p/1 p/2 p/3 p/4 p/5 p/6 p/7 p/8 p/9 p/10 p/11 p/12 ]
]
mixed: does [
profile/count/show [
[compose tuples/(length? p)]
[compose copy/part tuples-copy-compose length? p]
[reduce tuples-reduce/(length? p)]
[reduce copy/part tuples-copy-reduce length? p]
[collect [foreach byte to binary! p [keep byte]]]
] repetitions
]
mixed
; Count: 50000
; Time | Time (Per) | Memory | Code
; 0:00:00.176 | 0:00:00 | 4612096 | [reduce tuples-reduce/(length? p)]
; 0:00:00.185 | 0:00:00 | 4612096 | [compose tuples/(length? p)]
; 0:00:00.215 | 0:00:00 | 9224192 | [reduce copy/part tuples-copy-reduce length? p]
; 0:00:00.224 | 0:00:00 | 9224192 | [compose copy/part tuples-copy-compose length? p]
; 0:00:02.494 | 0:00:00 | 45301760 | [collect [foreach byte to binary! p [keep byte]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment