P
Phrogz
I was looking over the shoulder of a C++ coworker yesterday, when he
was writing a hack to only run certain code once. The C++ code was the
equivalent of the following Ruby code:
already_run = false
while true
foo = bar if !already_run
already_run = true
do_something( )
end
I asked him: "Wouldn't it be slightly faster to nest the boolean
assignment inside the if statement?" I was suggesting the equivalent
of:
already_run = false
while true
if !already_run
foo = bar
already_run = true
end
do_something( )
end
His answer was "no", and involved discussion of super-scalar
architectures and the fact that the original way ran the assignment in
parallel to the condition evaluation, and so was in fact faster.
The reason I'm posting is - are there any such considerations in Ruby
(when writing Ruby code, not C/C++ components)?
Or am I correct in assuming that the current state of
compilation/interpretation is such that there is no parallel branching
of statements to worry about?
was writing a hack to only run certain code once. The C++ code was the
equivalent of the following Ruby code:
already_run = false
while true
foo = bar if !already_run
already_run = true
do_something( )
end
I asked him: "Wouldn't it be slightly faster to nest the boolean
assignment inside the if statement?" I was suggesting the equivalent
of:
already_run = false
while true
if !already_run
foo = bar
already_run = true
end
do_something( )
end
His answer was "no", and involved discussion of super-scalar
architectures and the fact that the original way ran the assignment in
parallel to the condition evaluation, and so was in fact faster.
The reason I'm posting is - are there any such considerations in Ruby
(when writing Ruby code, not C/C++ components)?
Or am I correct in assuming that the current state of
compilation/interpretation is such that there is no parallel branching
of statements to worry about?