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

[REBOL] Re: RFC: Cross-language benchmark proposal

From: carl:cybercraft at: 8-Nov-2002 19:11

On 08-Nov-02, Joel Neely wrote:
> Suppose I wanted to test > how efficiently some language handled looping and simple arithmetic, > and so wrote something like the following: > loop-and-add: func [n [integer!] /local t i sum] [ > t: now/time/precise > i: sum: 0 > loop n [ > sum: sum + i: i + 1 > ] > t: to-decimal now/time/precise - t > print [n sum t] > ] > I might also want to test how efficiently the language handled > recursion, and so might write something like this: > recur-and-add: func [n [integer!] /local t sum] [ > t: now/time/precise > sum: _recur-and-add 0 n > t: to-decimal now/time/precise - t > print [n sum t] > ] > _recur-and-add: func [t [integer!] n [integer!]] [ > either n = 0 [t] [_recur-and-add t + n n - 1] > ] > If another programmer came along and observed, "You know that > you can perform the computation of both of these functions faster > with this: > triangle-sum: func [n [integer!]] [print [n n + 1 * n / 2 0]] > so why not use that instead?", then I'd have to respond, "Because > I want to see how smart the compiler/interpreter is, not test my > own abilities." > OTOH, if the compiler/interpreter had an optimizer that could > accept the sources for LOOP-AND-ADD and RECUR-AND-ADD and auto- > matically transform either/both into TRIANGLE-SUM, then I'd be > very happy indeed with the implementation! > Same issue as with tail-recursion-elimination (an issue which > comes up on the list every so often). As human programmers go, > it should be old news, but it's still significant to know > whether a given language implementation can do it automatically.
Those are good points. I do think there's room for both "Standard" and "Custom" algorithms though, as they show up different strengths in a language. The standard ones could be considered to be comparing raw performance, whereas with the custom ones you'd be comparing how programmers would normally approach a given problem in the different languages. What would be considered a normal approach is subjective of course, but if the committee in charge of choosing an example all agree that it's both readable and elegant and not unusually tricky code, then that should be good enough. I feel custom code would give a better indication of developement time and ease of maintainance than standard algorithms, as well as showing off "the REBOL way" of writing code. -- Carl Read