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

[REBOL] Re: Loop with negative count

From: pwawood::gmail::com at: 28-Dec-2006 10:50

Tim Why don't you protect your code against changes in undocumented behaviour by either using: Loop max 0 possible-negative-count or if positive? count [loop count [code]] I thought that there would be a time penalty in doing so but my tests show it is hardly noticeable. (Providing my tests are correct). Regards Peter Test Source: REBOl [] count: to integer! ask "Enter an integer - positive of negative: " times: 100000 start: now/time/precise loop times [ test: copy [] loop count [append test "hello"] ] end: now/time/precise print "test 1" print [times "loops with count of " count " took: " subtract end start] start: now/time/precise loop times [ test: copy [] loop max 0 count [append test "hello"] ] end: now/time/precise print "test 2" print [times "loops with count of " count " took: " subtract end start] start: now/time/precise loop times [ test: copy [] if positive? count [loop count [append test "hello"]] ] end: now/time/precise print "test 3" print [times "loops with count of " count " took: " subtract end start]
>> do %tt.r
Script: "Untitled" (none) Enter an integer - positive of negative: 2 test 1 100000 loops with count of 2 took: 0:00:02.404771 test 2 100000 loops with count of 2 took: 0:00:02.365083 test 3 100000 loops with count of 2 took: 0:00:02.41553
>> do %tt.r
Script: "Untitled" (none) Enter an integer - positive of negative: 8 test 1 100000 loops with count of 8 took: 0:00:08.297555 test 2 100000 loops with count of 8 took: 0:00:07.476637 test 3 100000 loops with count of 8 took: 0:00:07.236025
>> do %tt.r
Script: "Untitled" (none) Enter an integer - positive of negative: -4 test 1 100000 loops with count of -4 took: 0:00:00.843843 test 2 100000 loops with count of -4 took: 0:00:00.683992 test 3 100000 loops with count of -4 took: 0:00:00.466519
>> do %tt.r
Script: "Untitled" (none) Enter an integer - positive of negative: -55 test 1 100000 loops with count of -55 took: 0:00:00.902979 test 2 100000 loops with count of -55 took: 0:00:00.600534 test 3 100000 loops with count of -55 took: 0:00:00.513414
>> do %tt.r
Script: "Untitled" (none) Enter an integer - positive of negative: 30 test 1 100000 loops with count of 30 took: 0:00:37.077424 test 2 100000 loops with count of 30 took: 0:00:33.583799 test 3 100000 loops with count of 30 took: 0:00:38.293701