r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Profiling] Rebol code optimisation and algorithm comparisons.

Maxim
17-Sep-2009
[1]
interesting for those who didn't know, same result, but 2.5 times 
faster :


>> s: now/precise loop 1000000 [to-pair 2] print difference now/precise 
s
0:00:00.547

>> s: now/precise loop 1000000 [1x1 * 2] print difference now/precise 
s
0:00:00.219
Geomol
17-Sep-2009
[2]
And this comes in between:
to pair! 2
Sunanda
17-Sep-2009
[3]
And as-pair [2 2] is significantly slower than either.

Nice tuning experiment! There will be other surprises too, I'm sure.
Maxim
17-Sep-2009
[4x3]
I created this group, cause ever so often these experiments come 
around and we loose them... this should become a quick repository 
of tests & disussion for profiling discoveries we do.


any test should provide the full test command-line code, so its easier 
for other to copy-paste & compare without having to re-type.


ever so often, a compilation should be done, highlighted in a different 
color for easy referral...
integer to pair convertion speed tests:


>> s: now/precise loop 1000000 [to-pair 2] print difference now/precise 
s
0:00:00.547

>> s: now/precise loop 1000000 [1x1 * 2] print difference now/precise 
s
0:00:00.219

>> s: now/precise loop 1000000 [to pair! 2] print difference now/precise 
s
0:00:00.328

>> s: now/precise loop 1000000 [as-pair 2 2] print difference now/precise 
s
0:00:00.937
probably should add Rebol version and platform in any further profiling 
compilations... to make them even more usefull as a reference.
BrianH
17-Sep-2009
[7]
AS-PAIR and TO-PAIR are mezzanine. Carl has mentioned wanting to 
make AS-PAIR native - sounds like a good candidate.
Gabriele
19-Sep-2009
[8]
http://motoko.rebol.it/to-pair.png
Steeve
19-Sep-2009
[9]
Gabriele, could be useful to build a GUI like yours to standardize 
our benchmarks.
Gabriele
20-Sep-2009
[10]
my framework for tests and benchmarks will be released... eventually 
:)
Maxim
20-Sep-2009
[11]
neat  :-)
Maxim
29-Oct-2009
[12]
any one know of a faster method than sorting a block to get the largest 
value inside of it?

in my tests... this:
     forall blk [ val: max val first blk]

is ~ five times SLOWER than this:
     last sort blk
Steeve
29-Oct-2009
[13]
For R2 ?
Abracadabra !!!!
>> maximum-of
Maxim
29-Oct-2009
[14x2]
darn ... how could I have missed that func for years!
thx.
Steeve
29-Oct-2009
[16]
dunno ;-)
Maxim
29-Oct-2009
[17]
is there an equivalent for sum?
Steeve
29-Oct-2009
[18x2]
Ah, you're requesting that the math operators apply on blocks of 
scalar (vectors).
Old request.
Never done in R2 and not yet in R3
Moreover, maximum-of and minimum-of are probably the only ones functions 
faster with R2 than R3.

In R3, they have been turned back into mezzanines (never understood 
why)
Maxim
29-Oct-2009
[20x2]
here is a sreen dump of iteration vs maximum-of native use....  goes 
to show the speed difference in binary vs interpreted!!


>> a: [1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 
7 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 110 110]

report-test  profile :maximum-of reduce [a]
----------------
performed: 10000000 ops within 0:00:09.781 seconds.
speed: 1022390.34863511 ops a second
speed: 34079.678287837 ops a frame
----------------

>> report-test  profile :get-largest reduce [a]
----------------
performed: 10000 ops within 0:00:01.86 seconds.
speed: 5376.34408602151 ops a second
speed: 179.21146953405 ops a frame
----------------

we are talking 190 TIMES faster here
btw


'PROFILE is a handy function I built which accepts ANY function with 
ANY args and repeats the test until it takes longer than one second, 


you can adjust its loop scaling by varying amplitude and magnitude 
of loops at each iteration.


'REPORT-TEST simply dumps human-readable and easy to compare stats 
of calls to profile (which returns a block of info on the test).
Steeve
29-Oct-2009
[22x2]
actually, you are not sorting or traversing a long serie.
>>reduce [a]
== [[1 1 1 2 2 2 ...]]

your serie contains only one value.

i suggest to do a COPY A instead
tired ?
Maxim
29-Oct-2009
[24x2]
hehe
but no, the way profile handles its second argument (here reduce 
[a])  is that it uses the second argumet AS the argument spec for 
the function... 

loop i compose/only [ (:func) (args)]

so in the end, the test becomes:

loop i [maximum-of a]
Steeve
29-Oct-2009
[26]
ok
Maxim
29-Oct-2009
[27x4]
so I can test functions with any number of args, as long as I don't 
use refinements, I'm ok.
but I guess I could try using paths as the function argument... that 
actually might work too.
I'm working on isometric rendering of 3 polygonal gfx in AGG, so 
profiling is currently quite high on my list   :-)
*3D*
Steeve
29-Oct-2009
[31]
Do you use the skew command in draw ? or are you calculating the 
coordinates of your 3D objects for each layer.

(I think SKEW allow to simulate isometric rendering in AGG, but it's 
just an assumption, i never tried it)
Sunanda
29-Oct-2009
[32]
If you are trying to find the largest in a series of not-strictly 
comparable items, then be aware that R2 behaves differently to R3:
     b: reduce [1 none 12-jan-2005 unset 'a copy []]
     last sort b       ;; r2 and r3 agree
     maximum-of  b   ;; r3 has a headache
== [[]]
Steeve
29-Oct-2009
[33]
maximum-of uses the func GREATER? in R3
To me it make sense, because in Rebol, blocks are really great !
:-)
Maxim
29-Oct-2009
[34x5]
steeve, replied in (new) !SCARE group
I'm doing an in-depth analysis of various looping funcs... and discovering 
some VERY unexpected results amongst the various tests... will report 
in a while when I'm done with the various loop use cases.
the main one being that foreach is actually the fastest series iterator!
and remove-each is 90 times faster if it always return true rather 
than false !
(probably exponentially faster as the series grows)
Maxim
30-Oct-2009
[39x2]
wow I'm already at 7kb of output text with notes and proper header 
... I haven't done half the tests yet!
did you know that FOR is 60x ... let me write that out ... SIXTY 
TIMES slower than REPEAT  !!!
Geomol
30-Oct-2009
[41]
Yeah, there's often a huge difference between a mezzanine function 
and a native. In R2, FOR is mezz, REPEAT is native.
Maxim
30-Oct-2009
[42x9]
the comment above about remove-each is false... it was a coding error.
but I'm discovering a lot of discrepancies in things like string 
vs block speed of certain loops... 
and a lot of other neat things like:

pick series 1   

is  15% faster  than

not tail? series
1000 < i: i + 1     is     10%  faster than    (i: i + 1) > 1000
and its not because of the paren... I checked that....
(i: i + 1) > 1000       same speed as      i: i + 1   i > 1000
profiling almost done... my machine has been looping series and indexes 
non-stop for about 8 hours now  :-)


be ready for the most in-depth analysis on loops ever done for R2 
 ;-)
will be nice to do the same exercise on R3
See who is the overall winner in this REBOL iterator slug fest analysis!!!
   

over 8 hours of practically non-stop cpu cycling over a wide variety 
of exit conditions, datasets and ALL iterators in rebol 2 

(loop, repeat, for, forever, foreach, remove-each, forskip, forall, 
while, until )

20 kb of data, statistics, comments and test details.

INVALUABLE data for people wanting to optimize their REBOL code.


http://www.pointillistic.com/open-REBOL/moa/scream/rebol-iterator-comparison.txt
I would a few peer reviews so I can continue to evolve this document 
in order to make it as precise/usefull for everyone.