Hello, Rebols,

did anyone notice the time differences like this?:

>> st/start a: empty-il for i 1 20000 1 [a: prepend i a] st/stop
== 0:00:03
>> st/start a: copy [] for i 1 20000 1 [insert a i] st/stop
== 0:01:36

NB Insert is native as opposed to Prepend written in Rebol

the code follows:

; An empty IL
empty-il: make object! [
    ;Private elements, do not touch!
    what: nxt: none
]
; Basic manipulations
il-empty?: func [il] [none? il/nxt]
il-first: func [il] [
    either il-empty? il [
        print {Error, trying to get the first element of an empty
IL.}
        halt
    ] [il/what]
]
prepend: func [elem il] [
    make empty-il [what: elem nxt: il]
]
il-next: func [il] [
    either il-empty? il [
        print {Error, trying to shorten an empty IL.} halt
    ] [il/nxt]
]

; stopwatch with multiple timings
st: make object! [
    times: empty-il
    start: func [] [times: prepend now/time times]
    stop: func [/local t] [
        t: now/time - il-first times
        times: il-next times
        t
    ]
    clear: func [] [times: empty-il]
]

Reply via email to