Two issues are addressed here, first how to compare and second what to
compare.

A. How?
Most of the time the comparison of efficiencies of solutions is done by
        ts=: 6!:2 , 7!:2@
These two figures indicate the time and space of execution.

If the efficiency of the verbs v0, v1, ... have to be compared, it should be
very helpful to have one figure per verb and rank the verbs accordingly. For
that reason, and triggered by Miller's remark in
http://www.jsoftware.com/pipermail/programming/2007-August/007815.html, I
developed the Relative Performance indicator.

First determine scores by
        scores=:(5 ts 'x ',' y',~]) &> 'v0';'v1';....

If the example from Miller's post was used, I get
   [scores=:(5 ts ,& ' ''abcdefghijklmnopqrst''')&> 'ps2';'ps3'
  1.346865    90327552
0.55932564 1.2099904e8

Then the ranking by
        rnkng=:( [:(,.~([:(,.~/:@/:) */"1)) (%<./)"1 &.|:) scores

The ranking determines the execution time and space, together wit their
product, and divides it by the respective minima. In the above case:

   [rnkng=:('place';'rlprfm';'rlet';'rles'),,:',0.2,0.2,0.2'(8!:1)
([:(,~/:@/:@{.) [:(%<./)"1(,~*/)) &.|: scores           NB. line wrap
+-----+------+----+----+
|place|rlprfm|rlet|rles|
+-----+------+----+----+
|1    |1.80  |2.41|1.00|
|0    |1.00  |1.00|1.34|
+-----+------+----+----+

        NB. Miller (also) got 42% faster and 134% more space.
Now it is immediately obvious which one is faster and which one is leaner
and by which percentage. The product of the two determines the relative
performance. 
One could introduce extra weight factors if time or space is more important.
   NB. I remember that others, like Bron, used the concept of rlet and rles
before.


B. What?
There was a discussion
(http://www.jsoftware.com/pipermail/programming/2007-August/007816.html)
whether (the output of) verbs - and so their performances - were comparable
or not. 

Therefore I come up with a condition for two verbs v0 and v1 to be
comparable:
        1 = x (v0 -:&([:/:~ [:;L:1^:L. ,L:0) v1) y
Like
   (ps2 -:&([:/:~ [:;L:1^:L. ,L:0) ps3)'abcdefghijklmnopqrst'
1

Notice that this condition is necessary, but (perhaps) not sufficient. 


R.E. Boss




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to