[Thread Prev] [Thread Next]
Mike, I never knew that there would be a difference in speed
between using a slider vs. a local or global variable, and I find
this very interesting.
I just ran a couple of comparison tests to see how much difference
there is. Here are the test procedures I used, and the results on
my machine.
COMPARISON 1:
(The turtle repeatedly moves forward by the amount of the variable
and draws a square over and over again. Slider's value is set to
50.)
to test_local_variable
let [x speed]
pd
resett
repeat 5000 [fd :x rt 90]
show timer
end
to test_slider
pd
resett
repeat 5000 [fd speed rt 90]
show timer
end
RESULT:
Local variable: timer = 153 (roughly 15 seconds)
Slider as variable: timer = 202 (roughly 20 seconds)
Difference in speed: It takes the turtle roughly 33% longer to
complete its task when the slider is used for the variable.
COMPARISON 2:
(The turtle adds 1 to the value with each repetition and draws a
square spiral. In the case of the slider, we see the slider's
value continually increasing. Starting value is 1. Maximum
slider value exceeds 1000 so turtle can do 1000 repetitions.)
to test_local_variable_2
let [x speed]
pd
resett
repeat 1000 [fd :x rt 90 make "x :x + 1]
show timer
end
to test_slider_2
pd
resett
repeat 1000 [fd speed rt 90 setspeed speed + 1]
show timer
end
RESULT:
Local variable: timer = 39 (roughly 4 seconds)
Slider as variable: timer = 92 (roughly 9 seconds)
Difference in speed: It takes the turtle more than twice as long
(roughly 125% longer) to complete its task when the slider is used
for the variable.
COMPARISON 2A:
When I ran the Comparison 2 test again with a different turtle
shape and a larger turtle size (160), then there was actually not
as great a difference in speed:
Local variable: timer = 82 (roughly 8 seconds)
Slider as variable: timer = 137 (roughly 14 seconds)
Difference in speed: It takes the large turtle roughly 67% longer
to complete its task when the slider is used for the variable.
In all comparisons, the turtle visually moved slower when the
slider was used as the variable.
I suppose, when deciding whether or not to use a slider as a
variable, one needs to weigh these factors:
1) number of repetitions (The difference in speed matters much
less if the task is finished in less than a few seconds in either
case.)
2) need for speed (Even with thousands of repetitions, is there a
need to maximize speed?)
3) nature of the task (Some tasks involve a greater difference in
speed than others.)
4) visualization (Is the value changing, and is there a need for
the user to see the changing value of the slider?)
5) conceptual understanding of the programmer (Is it worth
teaching this technique to beginning students of MW? If not, then
when?)
Wendy
> -----Original Message-----
> From: mike sandy [mailto:mjsandy@xxxx]
> Sent: Friday, November 02, 2001 2:10 PM
> To: MWcybercourse
> Subject: Variables
>
>
> MW uses the slider as a variable for transmitting
> values to a program. There can be a considerable
> gain in speed if the slider value is transferred to a
> local or global variable such as :x and this used
> in the body of the program.
> Thus:
> to start
> let [x slider.....]
> calls to procedures using :x
> end
>
> Mike
Previous by thread:
Variables
Next by thread:
RE: Variables
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|