Hi all,

I made simple performace measurement of a few methods with the same effect:

--------------<begin code>--------------
profile: func [
 blk n
 /local st
][
 st: now/time/precise
 loop n blk
 print [n "cycles took" now/time/precise - st]
]

methods: [
 [mystring: "123456" mystring: head remove back tail mystring]
 [mystring: "123456" mystring: copy/part mystring ((length? mystring) - 1)]
 [mystring: "123456" copy/part mystring ((length? mystring) - 1)]
 [mystring: "123456" copy/part mystring skip tail mystring -1]
 [mystring: "123456" copy/part mystring at tail mystring -1]
 [mystring: "123456" mystring: head reverse remove head reverse mystring]
 [mystring: "123456" mystring: head remove at mystring length? mystring]
]


foreach m methods [
 print ["measuring method:" mold m]
 profile m 10'000'000
]

--------------<end code>--------------

results on my machine:

measuring method: [mystring: "123456" mystring: head remove back tail
mystring]
10000000 cycles took 0:00:11.953
measuring method: [mystring: "123456" mystring: copy/part mystring ((length?
mystring) - 1)]
10000000 cycles took 0:00:17.407
measuring method: [mystring: "123456" copy/part mystring ((length?
mystring) - 1)]
10000000 cycles took 0:00:16.406
measuring method: [mystring: "123456" copy/part mystring skip tail
mystring -1]
10000000 cycles took 0:00:16.828
measuring method: [mystring: "123456" copy/part mystring at tail
mystring -1]
10000000 cycles took 0:00:16.86
measuring method: [mystring: "123456" mystring: head reverse remove head
reverse mystring]
10000000 cycles took 0:00:23.219
measuring method: [mystring: "123456" mystring: head remove at mystring
length? mystring]
10000000 cycles took 0:00:14.187

...so it looks 'head remove back tail mystring' is the fastest one for now.

feel free to add your different methods and post results here!

regards,

Cyphre


----- Original Message -----
From: "Gregg Irwin" <[EMAIL PROTECTED]>
To: "PeterWAWood" <[EMAIL PROTECTED]>
Sent: Tuesday, December 14, 2004 6:40 PM
Subject: [REBOL] Re: Best way to remove the last character from a string?


>
> Peter et al,
>
> P> I've worked out two ways to chop-off the last character of a string.
> ...
> P> Can anyone suggest a less verbose, clearer and quicker way for me?
>
> This is a great topic for general discussion of a CHOP mezzanine!
>
> I'm sure a lot of us have them, and different ones for different uses.
> If we can come up with a good one, then we can propose it to RT for
> inclusion in REBOL. The trick is that it must be a good, flexible
> function (IMO).
>
> Thoughts:
>
>     Chop n items from head, tail, or both (default: tail)?
>
>     Chop at an arbitrary position in the series, or just use
>     AT when you make the call?
>
>     n can be a number other than one, but default behavior
>     is to chop one item?
>
>     Should the series be copied, or altered in place?
>
>     Return the item(s) removed, or should that be a different
>     function (PULL, CUT)?
>
>
> -- Gregg
>
> --
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
>
>

-- 
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.

Reply via email to