How can we found that a assignment to variable is fast using assign statement as compared to another method? Please explain.
-
Duplicate of https://stackoverflow.com/questions/17109045/what-is-the-efficiency-of-an-assign-statement-in-progress-4gl – Austin Jun 26 '20 at 10:53
3 Answers
Of course it depends on what it is that you are assigning and how many individual statements you are grouping together. But a simple example of comparing the difference is easy enough to put together:
define variable i as int64 no-undo.
define variable x1 as int64 no-undo.
define variable x2 as int64 no-undo.
define variable x3 as int64 no-undo.
define variable x4 as int64 no-undo.
define variable x5 as int64 no-undo.
etime( yes ).
do i = 1 to 10000:
assign
x1 = i
x2 = i
x3 = i
x4 = i
x5 = i
.
end.
message "with a grouped ASSIGN:" etime.
etime( yes ).
do i = 1 to 10000:
x1 = i.
x2 = i.
x3 = i.
x4 = i.
x5 = i.
end.
message "without ASSIGN:" etime.
FWIW:
On a modern release of Progress I would not expect to see much difference. Even in a benchmark designed to show such things. Quite a few things which were slow and needed to be optimized 30 years ago no longer need that kind of micro-optimization.
I would expect that any difference that still exists is even harder to find in realistic code. (The example above is not very realistic.) Sure, there are probably a few specific cases where it is a useful performance optimization. But I wouldn't use "performance" as an excuse to be doing this. The link that Austin points to - what is the efficiency of an assign statement in progress-4gl provides better reasons.

- 13,405
- 2
- 27
- 33
-
measuring performance with only 10 thousand iterations and etime gets a downvote from me ;-) – Stefan Drissen Jun 26 '20 at 14:23
-
1The numbers are consistent as you add zeros. I checked ;). And, hey! I upvoted your answer even though you used pre-processors :(. I like that you always remember to provide a link to the abldojo – Tom Bascom Jun 26 '20 at 15:05
Just throwing this pointless benchmark - which at a minimum you should have put in your question to start asking something meaningful - out there for further debate:
def var dt as datetime no-undo extent 4.
def var ic as int no-undo initial {&sequence}.
def var cc as char no-undo.
&scoped-define iterations 10000000
dt[{&sequence}] = now.
do ic = 1 to {&iterations}:
cc = "hello".
end.
dt[{&sequence}] = now.
cc = "".
dt[{&sequence}] = now.
do ic = 1 to {&iterations}:
assign cc = "hello".
end.
dt[{&sequence}] = now.
message
interval( dt[2], dt[1], "milliseconds" ) skip
interval( dt[4], dt[3], "milliseconds" )
.
https://abldojo.services.progress.com:443/#/?shareId=5ef603c34b1a0f40c34b8c63
For 10,000,000 (ten million) iterations of the above nonsense, the assign version takes 2392 ms and the non-assign version takes 2469 ms -> that's a saving of 77 milliseconds -> the plain performance is irrelevant and heavily outweighed by factors mentioned in Tom's earlier answer about readability and intent.
You /may/ have a case in which this is relevant, in which case you will need to do your own measuring.

- 3,266
- 1
- 13
- 21
There are a lot of advantages to using the keyword, and you can definitely read more in detph here: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/assign-statement.html
As for my personal experience, I can say this: I don't have benchmarks to be sure they're actually faster, but I'd say the benefits of using the ASSIGN statement are more related to transaction/behavior control. With the assign statement you can use the NO-ERROR option, for example, which allows you to treat possible problems with the values you're using.
I'd say it's also a matter of language aesthetic. Single line assigns without the keyword will do the job. But it will probably look sloppier.

- 1,463
- 8
- 13