Created
February 9, 2023 18:43
-
-
Save hiiamboris/c29f1d4f315a760a103b4bb46b48c183 to your computer and use it in GitHub Desktop.
R3/Red cross profiling parse test
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
REBOL [] Red [] | |
using-replace: func[str][ | |
replace/all str "??" #"¿" | |
replace/all str "!!" #"¡" | |
replace/all str "a'" #"á" | |
replace/all str "e'" #"é" | |
replace/all str "i'" #"í" | |
replace/all str "o'" #"ó" | |
replace/all str "u'" #"ú" | |
replace/all str "u:" #"ü" | |
replace/all str {u"} #"ü" | |
replace/all str "n'" #"ñ" | |
replace/all str "n~" #"ñ" | |
str | |
] | |
start-ch: charset "?!aeioun" | |
using-parse-collect: func[str /local out][ | |
out: make string! length? str | |
parse str [ | |
collect into out any [ | |
keep to start-ch [ | |
"??" keep (#"¿") | |
| "!!" keep (#"¡") | |
| "a'" keep (#"á") | |
| "e'" keep (#"é") | |
| "i'" keep (#"í") | |
| "o'" keep (#"ó") | |
| "u'" keep (#"ú") | |
| "u:" keep (#"ü") | |
| {u"} keep (#"ü") | |
| "n'" keep (#"ñ") | |
| "n~" keep (#"ñ") | |
| keep 1 skip | |
] | |
keep to end | |
] | |
] | |
out | |
] | |
;; With some longer input data... | |
st: {??Quie'n me librara' de la vergu:enza y la muerte? Cada man~ana alabare' al Sen'or. !!Aleluya!} | |
st1000: make string! 1000 * length? st | |
insert/dup st1000 st 1000 | |
either rebol [ | |
profile/times [[using-replace copy st1000]] 100 | |
profile/times [[using-parse-collect st1000]] 5000 | |
][ | |
clock/times [using-replace copy st1000] 10 | |
clock/times [using-parse-collect st1000] 500 | |
] |
There is a bug in the original test (missing |
before keep to end
) that made it stop after 1st replacement.
In fairer comparison code regardless of GC state Red (100ms) is only about 6x slower than R3 (14ms), which is acceptable for now:
REBOL [] Red []
; recycle/off
start-ch: charset "?!aeioun"
using-parse-collect: func[str /local out][
out: clear {}
parse str [collect after out [
any [
keep to start-ch [
"??" keep (#"¿")
| "!!" keep (#"¡")
| "a'" keep (#"á")
| "e'" keep (#"é")
| "i'" keep (#"í")
| "o'" keep (#"ó")
| "u'" keep (#"ú")
| "u:" keep (#"ü")
| {u"} keep (#"ü")
| "n'" keep (#"ñ")
| "n~" keep (#"ñ")
| keep skip
]
]
keep to end
]]
out
]
;; With some longer input data...
st: {??Quie'n me librara' de la vergu:enza y la muerte? Cada man~ana alabare' al Sen'or. !!Aleluya!}
st1000: make string! 4000 * length? st
take append st1000 "¿"
insert/dup st1000 st 1000
either rebol [
profile/times [[loop 10 [using-parse-collect st1000]]] 10
][
clock/times [using-parse-collect st1000] 10
]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It does not make sense to use number above 1000 in the
profile/times
call... see the source:https://github.com/Oldes/Rebol3/blob/417992081c5608cc55c07df3a98f858bc67e750c/src/mezz/mezz-debug.reb#L182-L184