Comments on: Simpler time difference function

Carl Sassenrath, CTO
REBOL Technologies
13-Aug-2009 5:31 GMT

Article #0233
Main page || Index || Prior Article [0232] || Next Article [0234] || 4 Comments || Send feedback

In A77 you can divide by time. I'm not sure why we didn't allow this earlier, but it's handy. Here's an example of why.

This is a handy piece of code for roughly measuring the time difference between two expressions:

diff-time: funct [reps [integer!] b1 [block!] b2 [block!]][
    t1: dt [loop reps b1]
    if zero? t1 [print "Use more repetitions." exit]
    t2: dt [loop reps b2]
    print [round/to t2 - t1 / t1 0.01% "slower"]

diff-time 1000000 [add 1.0 2.0] [add $1.0 $2.0]
13.13% slower

This code benefits from time division as well as the round to percent bug fix.

Now, I can use it for timing the speed of extension commands (natives):

secure [extension allow]
t: import %ext-test.dll

diff-time 1000000 [negate 1] [t-neg 1]
-6.84% slower
diff-time 1000000 [add 1 2] [t-addi 1 2]
-5.68% slower
diff-time 1000000 [add 1.0 2.0] [t-addd 1.0 2.0]
-10.61% slower

Ah ha! You have proof that extension commands are as fast (in fact a bit faster for some operations) than natives. Interesting, no? (The reason this happens is because the built-in actions like add must by polymorphic over so many datatypes, so extra conditional branching and dispatching occurs.)

Of course, keep in mind that results from this simple technique of measurement will vary due to multitasking activities of your system. Run your test a few times.



17-Aug-2009 8:41:02
Good Day friends, I am a novice to programing and just stumble on rebol and for past two days now, it has been wonderful experience,i dont know it could be this simple. p/s where can i download free rebol for biginners to get my hands on it, the links availabe to me are not working ( Please help!!!
Carl Sassenrath
17-Aug-2009 19:44:53
Chidi: I just checked the links at that URL, and they seem ok. What link did you find broken?
19-Aug-2009 7:33:14
Carl thank you so much for your reply, this is the link "" it is not opening with my browser, i have used Mozila firefox and Internet Explorer browser still it is not opening. Please if there is any other way I can download the free beginers version,I will appreciate it.
19-Aug-2009 11:48:56
Chidi: the link also works for me. You may be behind a firewall that is blocking you from accessing that URL.

The direct URL for downloading the most recent Windows View version of REBOL is:

Maybe that will work for you.

Post a Comment:

You can post a comment here. Keep it on-topic.


Blog id:



 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 24-Mar-2017 - Edit - Copyright REBOL Technologies -