World: r3wp
[Rebol School] Rebol School
older newer | first last |
Henrik 20-Mar-2010 [3045] | extend extends with a single value, where append can extend with any values. |
Davide 21-Mar-2010 [3046] | Just for fun (it's a slow sunday today) I've wrote a rebol version of the code used as benchmark in this page http://tinyurl.com/5nezt9 here's the code: REBOL [] person: make object! [ _count: none _prev: none _next: none _construct: func [n] [_count: n] get-prev: does [_prev] set-prev: func [pr] [_prev: pr] get-next: does [_next] set-next: func [nxt] [_next: nxt] shout: func [shout nth /local aux] [ if shout < nth [ return shout + 1 ] aux: get-prev aux/set-next get-next aux: get-next aux/set-prev get-prev 1 ] ] chain: make object! [ _first: none _last: none _construct: func [size /local current] [ repeat i size [ current: make person [] current/_construct i if none? _first [_first: current] if not none? _last [ _last/set-next current current/set-prev _last ] _last: current ] _first/set-prev _last _last/set-next _first ] kill: func [nth /local current shout] [ current: _first shout: 1 while [not equal? current current/get-next] [ shout: current/shout shout nth current: current/get-next ] _first: current ] ] start: now/precise iter: 100000 loop iter [ current-chain: make chain [] current-chain/_construct 40 current-chain/kill 3 ] print ["Time per iteration =" (difference now/precise start) / iter ] halt which give me: Time per iteration = 0:00:00.00080234 802 microsecond that is the slower time of the benchmark, but not SO slow, php is near with 593 microsecond, jython 632 ... .(the test system is pretty like mine so i can compare the result) There's a way to improve the performance? |
Henrik 21-Mar-2010 [3047] | if not = unless also perhaps: if none? _first [_first: current] = any [_first _first: current] not equal? = not-equal? Didn't check if there are some mezzanines in there, though. |
Davide 21-Mar-2010 [3048] | a bit better: Time per iteration = 0:00:00.00077844 |
Henrik 21-Mar-2010 [3049x2] | any instance of IF can possibly be replaced by ANY or ALL. |
get-prev: does [_prev] set-prev: func [pr] [_prev: pr] get-next: does [_next] set-next: func [nxt] [_next: nxt] These will also slow things down. I'm not sure if you can get rid of them. | |
Pekr 21-Mar-2010 [3051] | jython? So python version emulated in JAVA is faster than native REBOL? :-) |
Henrik 21-Mar-2010 [3052] | Davide, try an R3 version too. |
Davide 21-Mar-2010 [3053x3] | java is in the class of c++ in performance AFAIK I remember the in 1998 there was a mame - java applet that could run phoenix at 100% of the velocity with no skipframe (I had a pentium 100 Mhz at that time) |
using _prev and _next instead of function the result is: Time per iteration = 0:00:00.00056687 | |
with R3: Time per iteration = 0:00:00.00034359 | |
Geomol 21-Mar-2010 [3056] | I don't think, Java is as C++ in performace. C++ can be compared to C in performace, and Java is at least 8 times slower. See e.g.: http://www.timestretch.com/FractalBenchmark.html |
Henrik 21-Mar-2010 [3057] | R3 performance: Interesting. :-) |
Davide 21-Mar-2010 [3058] | Yes, I meant in the same class if compared to ruby, python or similar. java is slower than c++ (but I think that 8x slower is not realistic in common usage) |
Paul 21-Mar-2010 [3059] | David you can dump those mezzanines and just use make function! instead of 'does and 'func. Maybe use the operators such as <> instead of not equal? and use chain assignment here and there were applicable. |
Davide 21-Mar-2010 [3060] | a bit OT: yesterday I've discovered that compiled VB6 run as fast as tcc in number crunching :-) |
Steeve 21-Mar-2010 [3061] | http://tinyurl.com/5nezt9,already dead ? |
Davide 21-Mar-2010 [3062] | works here, the plain url is http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/ |
BrianH 21-Mar-2010 [3063x2] | Java is faster than REBOL at Java-style code, because REBOL is optimized for a different code style. If you are writing code in REBOL style then it can be faster than Java in some cases, or at least less slower in other cases. In this case what is slowing down REBOL is all of the unnecessary accessor code: OO overhead that Java can optimize away, but it REBOL you just don't write in the first place. |
On the other hand, you probably ran your tests on different hardware than he did, so time results may not be comparable :) | |
Janko 21-Mar-2010 [3065] | I know that rebol appeared to be the slowest language on debian language shootout , but then cheyenne is *much* faster webserver than any of the ones made in dynamic languages I tried (even lua). so speed is a relative thing it seems (like Brian says) |
Henrik 21-Mar-2010 [3066] | also when using dialects, there is often a huge speed gain, but you can't really code like that in most other languages. |
Davide 21-Mar-2010 [3067] | In this case, I think that we can be happy with performance too. |
Janko 13-Apr-2010 [3068] | Is there a way to pass a refinement further? so I don't have to do something like do-some: func [ /ref ] [ either ref [ do-more/ref ] [ do-more ] ] |
Ladislav 13-Apr-2010 [3069x2] | that is an oldie. In R3 as well as in R2+Rebcode you can use a native APPLY |
otherwise you are mostly "out of luck" | |
Janko 13-Apr-2010 [3071] | aha, my r2 doesn't seem to have apply.. I will solve it some other way :) thanks |
Ladislav 13-Apr-2010 [3072x2] | Well, the mezz. Apply may be quite slow, but if it suffices... |
Then you can download it somewhere | |
Janko 13-Apr-2010 [3074] | I will use normal argument .. I don't want to further complicate codebase to make it a little nicer |
Ladislav 13-Apr-2010 [3075] | http://www.rebol.org/view-script.r?script=apply.r |
BrianH 14-Apr-2010 [3076] | There's an APPLY in R2/Forward that replicates R3's APPLY native. Either the native or the R2/Forward version will be in 2.7.8. |
Maxim 14-Apr-2010 [3077x2] | janko, when I have chained calls which use options, I do this: func [/opta /optb /options oblk][ oblk: any [oblk copy [ ] ] if opta [append oblk 'opta] if optb [append oblk 'optb] ; then use the block exclusively using find. if find oblk 'opta [print "option A supplied" if find oblk 'optb [print "option B supplied" ; this way you can easily chain options do-something/options oblk ] |
oops... missing end "]" chars ... you know where. | |
Gregg 14-Apr-2010 [3079] | I've done the same thing as Max, and if there is just one refinement, I'll still use EITHER. If you have a scenario where there's an entry point that delegates work and requires multiple options, consider making it a dialected func. |
BrianH 14-Apr-2010 [3080x3] | The APPLY mezzanine in 2.7.7 has a minor, obscure bug that is fixed in a later R2/Forward release, and later R2 mezzanine source. But aside from that it works fine, and I have used it in production code with no errors (the bug was so obscure that it never came up in practice or testing). |
Maxim, you forgot to copy oblk. | |
Without APPLY or something like it, you end up having to do some tricky stuff sometimes. See this REMOLD backport for instance: remold: func [ "Reduces and converts a value to a REBOL-readable string." value [any-type!] "The value to reduce and mold" /only "For a block value, mold only its contents, no outer []" /all "Mold in serialized format" /flat "No indentation" ][ ; Nasty, but the best you can do without native APPLY do pick pick pick [[[ [mold reduce :value] [mold/flat reduce :value] ] [ [mold/all reduce :value] [mold/all/flat reduce :value] ]] [[ [mold/only reduce :value] [mold/only/flat reduce :value] ] [ [mold/only/all reduce :value] [mold/only/all/flat reduce :value] ]]] not only not all not flat ] ; Note: Uses APPLY in R3. | |
Maxim 14-Apr-2010 [3083] | good catch on the copy |
BrianH 14-Apr-2010 [3084] | And that REMOLD should be using get/any 'value instead of :value - an R3-ism that crept into the code. |
Maxim 14-Apr-2010 [3085] | is get/any 'value faster? |
BrianH 14-Apr-2010 [3086] | No, but it supports molding unset! values and errors. |
Maxim 14-Apr-2010 [3087] | ok, thought that was the reason |
BrianH 14-Apr-2010 [3088] | In R3 :value supports that - it means GET/any instead of GET. |
Maxim 14-Apr-2010 [3089] | cool! its easy to trip R2 when scanning blocks and an unset! value lies there |
BrianH 14-Apr-2010 [3090x2] | We did a *lot* to make R3 easier and more powerful :) |
Nevermind, I think the [any-type!] in R3's REMOLD is the error, not the :value in the backport. I'll fix it now and put in a ticket. | |
Steeve 14-Apr-2010 [3092] | See my beloved version :) remoldx: func [x /all /flat /only][ do head clear change change change next 'mold/? pick [[] all] not all pick [[] flat] not flat pick [[] only] not only reduce x ] |
BrianH 14-Apr-2010 [3093] | You forgot to copy 'mold/? :) |
Steeve 14-Apr-2010 [3094] | no, it doesn't matter because of the clear |
older newer | first last |