? lnBaseTime = seconds() for i = 1 to 1000000 endfor lnBaseTime = seconds() - lnBaseTime j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = -j endfor ? seconds() - lnSeconds - lnBaseTime, "negate" j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = 0 - j endfor ? seconds() - lnSeconds - lnBaseTime, "add/subtract" j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = j * -1 endfor ? seconds() - lnSeconds - lnBaseTime, "multiply/divide" j = 10000000 lnSeconds = seconds() for i = 1 to 1000000 j = -j endfor ? seconds() - lnSeconds - lnBaseTime, "negate with another value" lnSeconds = seconds() for i = 1 to 1000000 j = -i endfor ? seconds() - lnSeconds - lnBaseTime, "negate with another memvar" lnSeconds = seconds() for i = 1 to 1000000 j = -1 endfor ? seconds() - lnSeconds - lnBaseTime, "test constant assignment"and the theory holds, negate is 15% faster than add/subtract which is 4% faster than multiply/divide.
j = 1 lnSeconds = seconds() for i = 1 to 1000000 store -j to j endfor ? seconds() - lnSeconds - lnBaseTime, "store negate" j = 1 lnSeconds = seconds() for i = 1 to 1000000 store 0 - j to j endfor ? seconds() - lnSeconds - lnBaseTime, "store add/subtract" j = 1 lnSeconds = seconds() for i = 1 to 1000000 store j * -1 to j endfor ? seconds() - lnSeconds - lnBaseTime, "store multiply/divide"but the difference is 0.08 seconds on a million iterations (P4m 2.5ghz), I think I'll stick with with the less COBOLly = *g*
j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = -m.j endfor ? seconds() - lnSeconds - lnBaseTime, "m. negate" j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = 0 - m.j endfor ? seconds() - lnSeconds - lnBaseTime, "m. add/subtract" j = 1 lnSeconds = seconds() for i = 1 to 1000000 j = m.j * -1 endfor ? seconds() - lnSeconds - lnBaseTime, "m. multiply/divide"a difference of 0.01 seconds on a million iterations, again I'll stick with the more readable m-dotless version. This is affected too by currently open work areas, this test was done with no tables open. Bottomline, never take anyone's benchmarks for the Gospel truth, verify them for yourselves and weigh them according to your own situation.