|
Pages: [1]
|
 |
|
Author
|
Topic: speed up rebol code (Read 3424 times)
|
|
pepiporn
|
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: s: parse/all s ";" if error? try [ x: second s ] [ x: none ]
but much faster of course is 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
|
some people say insert tails is faster then append
is that true?
|
|
|
|
|
Logged
|
|
|
|
|
Ashley
|
'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: either cond [x: 1][x: 2]
the REBOL form of x: either cond [1][2]
is more compact (and readable). Another trick is to use 'pick in lieu of 'switch, as in: x: switch val [ 1 ["a"] 2 ["b"] 3 ["c"] ]
can be written as: x: pick ["a" "b" "c"] val
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
FOR is also a mezzanine function and so should be avoided where speed is important. for instance, instead of using... for n 1 1000000 1 []
use... repeat n 1000000 []
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
|
pepiporn
|
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
|
Performance checks? Add some simple timing code with prints. Here's an example: http://www.rebol.org/cgi-bin/cgiwrap/rebol...script=timeit.rI 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
|
Back to the original question 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: 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 : 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 : >> 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
|
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
|
Does length? count the data or is it known by rebol?
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
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
|
LENGTH? is O(1) for all series except LIST!. It is O(n) for LIST!.
|
|
|
|
|
Logged
|
|
|
|
|
fhein
|
sweet  using length? will make my code a little more readable
|
|
|
|
|
Logged
|
|
|
|
|
Sunanda
|
If you are still interested in speeding up code, take a look at rebcodehttp://www.rebol.net/article/0214.htmlIf your application has a lot of number crunching or bit twiddling, rebcode can help those sections by a order of magnitude.
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2241 Posts in 585 Topics by 2232 Members
Latest Member: ThortHoTeMorY
|