World: r3wp
[Rebol School] Rebol School
older newer | first last |
[unknown: 5] 2-Jan-2009 [1095x2] | But I would go with the more efficient code in that situation since it would be a mezz |
We can care less how long the code is in a mezz as long as it performs at the optimum. | |
Steeve 2-Jan-2009 [1097] | Brian, i wonder what will be the overhead if map was a mezzanine in R3 (you should test that too) ? |
BrianH 2-Jan-2009 [1098x2] | Since the profiling functions are better in R3, I am comparing the differences there. |
The either is faster. | |
[unknown: 5] 2-Jan-2009 [1100x2] | pick is usually faster than either when eithers first argument is logic based. |
which in this case it is | |
Steeve 2-Jan-2009 [1102] | ahah, i was thinking about pick too |
BrianH 2-Jan-2009 [1103] | Yes, but we have to calculate. Let me check that too. |
Steeve 2-Jan-2009 [1104] | but in that cas we have to pre-calculate length? data |
[unknown: 5] 2-Jan-2009 [1105x2] | Yes, I agree, alwasy profile - never assume |
at least when building mezzanines. | |
BrianH 2-Jan-2009 [1107] | I still want to backport the profiler to R2. |
Steeve 2-Jan-2009 [1108] | length? pick reduce [[1] data] word? word but there is an overhead too |
BrianH 2-Jan-2009 [1109] | Here's the fastest version for R2: map: func [ [throw] "Evaluates a block for each value(s) in a series and returns them as a block." 'word [word! block!] "Word or block of words to set each time (local)" data [block!] "The series to traverse" body [block!] "Block to evaluate each time" ] [ head foreach :word data reduce [ :insert :tail make block! either word? word [length? data] [divide length? data length? word] to paren! body ] ] |
Janko 2-Jan-2009 [1110] | btw: python was recieving criticism because guido made it more and more awkward to use functional programming , which wasn't handeled that well previoulsly either. The way you added a powerful (with variable number of params) map that looks like native in other languages really speaks something about a language. Interestingly this article about python also mentions REBOL http://lambda-the-ultimate.org/node/2302 |
BrianH 2-Jan-2009 [1111] | Interesting to see how much optimization expands the code, isn't it? |
Janko 2-Jan-2009 [1112] | yes :) |
Steeve 2-Jan-2009 [1113x2] | and [divide a b] is faster than [/ a b] ? |
lol | |
BrianH 2-Jan-2009 [1115x2] | LENGTH? is prefix, so to use the infix / you would need parens, which have overhead. |
I wouldn't use prefix / in a mezzanine - bad form. | |
Steeve 2-Jan-2009 [1117] | in R2 / works as prefix too |
BrianH 2-Jan-2009 [1118] | I can't profile them for comparison, because bad form like that has not removed from R3, where my profiling functions are better. |
Steeve 2-Jan-2009 [1119] | anyway... |
BrianH 2-Jan-2009 [1120] | has not -> has |
Steeve 2-Jan-2009 [1121] | it was a joke |
BrianH 2-Jan-2009 [1122x2] | has not -> has been I am bad at typing today. Let's not corrupt people in the school group :) |
Speaking of which, good catch on the foreach bind/copy eliminating an explicit copy :) | |
Steeve 2-Jan-2009 [1124] | yeah, i think too, i will have to remember that trick next time |
BrianH 2-Jan-2009 [1125x3] | Couldn't use it here efficiently, but a good trick nonetheless :) |
Btw, on R3 that EITHER WORD? trick has half the overhead of the TO-BLOCK method. | |
Not much either way, but we count our miliseconds when writing mezzanines. | |
Steeve 2-Jan-2009 [1128x2] | even with [to block!] ? |
the native one... | |
Janko 2-Jan-2009 [1130] | (thanks for interesting discussion and code, I have to go to sleep it's almost morning here), I will use map a lot :) |
BrianH 2-Jan-2009 [1131x2] | Yeah. The either trick saves 20 milliseconds and some memory too, on my slow computer. |
22 to 33 milliseconds, depending on input. | |
Steeve 2-Jan-2009 [1133] | it's a shame 'either has a so verbose form ;-) |
BrianH 2-Jan-2009 [1134] | This isn't C :) |
Steeve 2-Jan-2009 [1135x3] | nite Janko |
it"s hard work to optimize such short mezzanine | |
but it's funny too | |
BrianH 2-Jan-2009 [1138] | Indeed it is both, but well worth it :) |
Steeve 2-Jan-2009 [1139] | for my personnal use, i would have an option to modify the input serie instead of creating a new one |
BrianH 2-Jan-2009 [1140x2] | The R3 FOREACH is used for that. |
Still, good idea :) | |
Steeve 2-Jan-2009 [1142] | an /keep refinement on map ? |
BrianH 2-Jan-2009 [1143] | /no-copy |
Steeve 2-Jan-2009 [1144] | i want to see :) |
older newer | first last |