Rebol Talk Forum  |  Getting Started  |  Code Examples, Tips & Advice  |  Topic: speed up rebol code
Pages: [1] Print
Author Topic: speed up rebol code  (Read 3164 times)
pepiporn
Newbie
*
Offline Offline

Posts: 8


View Profile
speed up rebol code
« on: May 13, 2004, 03:13:29 PM »

are there any easy to implement tricks or guidlines or things you shall avoid  to speed up your rebol code?

for example at first i tend to use constructs like:

Code:
s: parse/all s ";"
if error? try [ x: second s ] [ x: none ]

but much faster of course is

Code:
s: parse/all s ";"
either < (length? s) 2 [ x: none ] [ x: second s ]

. ja. maybe a bad example, but i hope you get the key what i want.
Logged
pepiporn
Newbie
*
Offline Offline

Posts: 8


View Profile
speed up rebol code
« Reply #1 on: May 13, 2004, 04:18:05 PM »

some people say insert tails is faster then append

is that true?
Logged
Ashley
Newbie
*
Offline Offline

Posts: 37


View Profile
speed up rebol code
« Reply #2 on: May 13, 2004, 09:29:26 PM »

'append is a mezz, 'insert and 'tail are native. Quick test of 1,000,000 append vs insert tail yields 1.3s and .5s respectively.

I've also found that while I started writing code like:
Code:
either cond [x: 1][x: 2]
the REBOL form of
Code:
x: either cond [1][2]
is more compact (and readable). Another trick is to use 'pick in lieu of 'switch, as in:
Code:
x: switch val [
   1 ["a"]
   2 ["b"]
   3 ["c"]
]
can be written as:
Code:
x: pick ["a" "b" "c"] val
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
speed up rebol code
« Reply #3 on: May 14, 2004, 02:35:54 AM »

FOR is also a mezzanine function and so should be avoided where speed is important.  for instance, instead of using...
Code:
for n 1 1000000 1 []
use...
Code:
repeat n 1000000 []
Logged

- Carl Read
pepiporn
Newbie
*
Offline Offline

Posts: 8


View Profile
speed up rebol code
« Reply #4 on: May 14, 2004, 07:57:42 AM »

thanks a lot.

i hardly use for because i think foreach ismuch more comfortable

another question: how do you do this performance checks in the rebol console?  
Logged
Sunanda
Jr. Member
**
Offline Offline

Posts: 94


View Profile
speed up rebol code
« Reply #5 on: May 16, 2004, 07:39:14 AM »

Performance checks?

Add some simple timing code with prints.  Here's an example:

http://www.rebol.org/cgi-bin/cgiwrap/rebol...script=timeit.r

I tend not to worry about optimising at the code level. It is possible, but generally (in the sort of domains I'm working in -- yours may differ) it doesn't make much difference.

I do worry about optimising by picking the right algorithm. That can make a factor of 100 or more difference in application speed. But that's more of a computer science issue than a REBOL coding one.
Logged
DideC
Newbie
*
Offline Offline

Posts: 25


View Profile
speed up rebol code
« Reply #6 on: July 01, 2004, 07:51:23 AM »

Back to the original question
Quote
are there any easy to implement tricks or guidlines or things you shall avoid to speed up your rebol code?

for example at first i tend to use constructs like:

Code:
s: parse/all s ";"
if error? try [ x: second s ] [ x: none ]

The better way in this case is to use 'pick instead of 'second :
Code:
s: parse/all s ";"
x: pick s 2

Remember that 'first, 'second, 'third... return an error if out of data, but 'pick just return 'none in this case :
Code:
>> a: [1 2 3]
== [1 2 3]
>> pick a 1
== 1
>> pick a 3
== 3
>> pick a -1
== none
>> pick a 5
== none
>> fifth a
** Script Error: Out of range or past end
** Where: halt-view
** Near: fifth a
« Last Edit: July 01, 2004, 07:52:08 AM by DideC » Logged
Paul
Newbie
*
Offline Offline

Posts: 9


View Profile
speed up rebol code
« Reply #7 on: July 12, 2004, 09:15:24 AM »

Actually, its gonna be simple if the functions your comparing are mezz level vs native level.  But the best tool I use is trace.  Trace will show you how many steps are being processed by the interpreter.  So when I want to optimize a piece of code I start passing different functions through trace to get a feel for optimization.  Its a very handy tool in those situations.

Paul Tretter
Logged
fhein
Newbie
*
Offline Offline

Posts: 47


View Profile
speed up rebol code
« Reply #8 on: May 29, 2005, 09:10:40 AM »

Does length? count the data or is it known by rebol?
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
speed up rebol code
« Reply #9 on: May 30, 2005, 01:26:22 AM »

Quote
Does length? count the data or is it known by rebol?
REBOL would know the length of a series I'm sure.  If it didn't and had to count the values in it, longer series would take longer to find the length of, so you could test it by timing LENGTH? on short and (very) long series.
 
Logged

- Carl Read
Gabriele
Full Member
***
Offline Offline

Posts: 181


View Profile WWW
speed up rebol code
« Reply #10 on: May 30, 2005, 04:18:28 AM »

LENGTH? is O(1) for all series except LIST!. It is O(n) for LIST!.
Logged
fhein
Newbie
*
Offline Offline

Posts: 47


View Profile
speed up rebol code
« Reply #11 on: May 31, 2005, 04:53:47 PM »

sweet Tongue using length? will make my code a little more readable
Logged
Sunanda
Jr. Member
**
Offline Offline

Posts: 94


View Profile
speed up rebol code
« Reply #12 on: November 26, 2005, 06:57:06 AM »

If you are still interested in speeding up code, take a look at rebcode

http://www.rebol.net/article/0214.html

If your application has a lot of number crunching or bit twiddling, rebcode can help those sections by a order of magnitude.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Code Examples, Tips & Advice  |  Topic: speed up rebol code
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 19, 2008, 07:49:48 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2187 Posts in 576 Topics by 1615 Members
Latest Member: Uncellhoolf

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc