Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[to] to block! vs to-block

 [1/12] from: pwawood:mango:my at: 18-Nov-2004 11:09


In the discussion about handling "untrusted" data, I noticed that Gabriele used "to block!" whilst Sunanda used to "to-block". I'm trying to understand if this is just a matter of personal preference or there is a real difference. On my machine, to block! appears to be at least 15 percent quicker than to-block as shown by the following timing test. The test isn't very accurate because I had other applications loaded on the machine at the time. I did run a loop of 25 timing tests and to block! was always quicker. Regards Peter
>> speedy: [
[ time-to-block: make time! 0 [ time-to: make time! 0 [ [ loop 100 [ [ start: now/time/precise [ loop 1000 [ to-block "12345" ] [ end: now/time/precise [ time-to-block: time-to-block + end - start [ [ start: now/time/precise [ loop 1000 [ to block! "12345" ] [ end: now/time/precise [ time-to: time-to + end - start [ ] ; end loop 100 [ print [ "average time for to-block" (time-to-block / 100) ] [ print [ "average time for to block!" (time-to / 100) ] [ ] == [ time-to-block: make time! 0 time-to: make time! 0 loop 100 [ start: now/time/precise loop 1000 ...
>> do speedy
average time for to-block 0:00:00.0067641 average time for to block! 0:00:00.00569063
>> do speedy
average time for to-block 0:00:00.00674169 average time for to block! 0:00:00.00503805
>> do speedy
average time for to-block 0:00:00.00682156 average time for to block! 0:00:00.00574013

 [2/12] from: carl:cybercraft at: 18-Nov-2004 5:51


On Thursday, 18-Novenber-2004 at 11:09:38 you wrote,
>In the discussion about handling "untrusted" data, I noticed that >Gabriele used "to block!" whilst Sunanda used to "to-block". I'm trying
<<quoted lines omitted: 5>>
>time. I did run a loop of 25 timing tests and to block! was always >quicker.
Speed's the only difference, as TO-BLOCK's just a function that duplicate's TO BLOCK! You can see this in the source of TO-BLOCK...
>> source to-block
to-block: func ["Converts to block value." value "Value to convert"][to block! :value] Carl Read.

 [3/12] from: pwawood::mango::net::my at: 18-Nov-2004 13:11


Carl Thanks. I should remember to check the source myself. I presume the reason for to-block's existence is that it is perceived to be more readable than to block! Regards Peter On Thursday, Nov 18, 2004, at 12:49 Asia/Kuala_Lumpur, Carl Read wrote:

 [4/12] from: SunandaDH:aol at: 18-Nov-2004 4:35


Peter:
> In the discussion about handling "untrusted" data, I noticed that > Gabriele used "to block!" whilst Sunanda used to "to-block". I'm trying > to understand if this is just a matter of personal preference or there > is a real difference.
I'd say it was preference. I'm not often writing code that needs to be optimised to run as fast as possible,and when I am, it's unlikely to be in REBOL) so I'm usually not worried by a few per cent here and there. Most, though not all "to-xxx" words are functions, but some are natives. You can see that with this: help "to" So there is no in principle reason why a later release can't make them all native. Also, it avoids losing a console session when you type the wrong thing. Don't try this on a session you want to keep: to routine! Sunanda.

 [5/12] from: rotenca::telvia::it at: 18-Nov-2004 19:30


Hi Sunanda,
> Also, it avoids losing a console session when you type the wrong thing. > Don't > try this on a session you want to keep: > > to routine! >
You should add it to RAMBO. --- Ciao Romano

 [6/12] from: SunandaDH::aol::com at: 18-Nov-2004 14:20


Romano:
> You should add it to RAMBO.
Thanks. I thought I'd sent it as a feedback ages ago. But I can't find any record of it, or anything matching in RAMBO, so I've just added it. Sunanda.

 [7/12] from: lmecir::mbox::vol::cz at: 18-Nov-2004 21:20


Peter WA Wood napsal:
>I presume the reason for to-block's existence is that it is perceived >to be more readable than to block! > >Regards > >Peter >
Maybe. It surely is a legacy matter, because in REBOL/Core 1.x.x we had only TO-BLOCK etc. functions. I think (personal opinion) that the TO function is a progress and am using it because it looks more readable to me. The speed difference is a bonus I am not taking into account. -L

 [8/12] from: antonr:lexicon at: 19-Nov-2004 18:41


Hi Peter, to-block One word, slower execution, more efficient storage to block! Two words, faster execution, less efficient storage I use to-block when I do not care about speed. About storage, think of all the instances in rebol code of to-block (and the others; to-string etc..) Internally, rebol can store these all as a single code, and thus reduce the size of the rebol executable. Two words obviously then take two codes. This will probably bear out in the upcoming ReBIN format, too. Anton.

 [9/12] from: pwawood::eidosnet::co::uk at: 19-Nov-2004 18:44

Re: [to vs to-] to block! vs to-block


Allen, Ladislav & Sunanda: Thanks for the additional explanations. Though Allen has now set me off on another path of Rebol discovery - understanding code size (or trying to would be more appropriate). I was always taught that small and fast are inextricably linked in the world of programming. Having only "to" would increase the size of scripts but it would also reduce the size of Rebol, perhaps a worthwhile trade-off? Romano: I submitted the "to routine!" bug via feedback. Regards Peter

 [10/12] from: SunandaDH:aol at: 19-Nov-2004 6:05

Re: [to] to block! vs to-block


Ladislav:
> It surely is a legacy matter, because in REBOL/Core 1.x.x we had only > TO-BLOCK etc. functions.
I'm surprised. What did the source look like, if it wasn't just wrapping a "to block!" ? Sunanda.

 [11/12] from: antonr:lexicon at: 20-Nov-2004 0:36


I can't find an old Rebol/Core 1.0 on my present system, but I guess they could have been natives, or using MAKE, eg: make block! "hello" ; == [hello] I think the algorithm to generate all the TO-xxx functions was made so that none of the datatypes would be forgotten (as well as using less code :) Anton.

 [12/12] from: greggirwin::mindspring::com at: 19-Nov-2004 10:43

Re: [to vs to-] to block! vs to-block


Hi Peter, PWW> Having only "to" would increase the size of scripts but it would also PWW> reduce the size of Rebol, perhaps a worthwhile trade-off? In this case, as in many others, the speed hit is due to the extra level of indirection/abstraction from the wrapper mezzanines. The size difference is minimal here, but I think the to-* functions could exist for other reasons. 1) Simplicity. You only have one arg to pass them. 2) TO is a very common word, and may be used in many different contexts (e.g. a range FROM a TO b, as a refinement in a function, etc. The to-* functions mean you don't have to use system/words/to in those cases. I think the size is probably minimal in the end (highly redundant source that is compressed). Only Carl can really say why they exist though. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted