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

[REBOL] Re: Best way to remove the last character from a string?

From: cyphre:seznam:cz at: 15-Dec-2004 8:21

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