what is the efficiency of an assign statement in progress-4gl

自闭症网瘾萝莉.ら 提交于 2020-01-15 11:53:31

问题


why is an assign statement more efficient than not using assign?

co-workers say that:

assign
  a=3
  v=7
  w=8.

is more efficient than:

a=3.
v=7.
w=8.

why?


回答1:


You could always test it yourself and see... but, yes, it is slightly more efficient. Or it was the last time I tested it. The reason is that the compiler combines the statements and the resulting r-code is a bit smaller.

But efficiency is almost always a poor reason to do it. Saving a micro-second here and there pales next to avoiding disk IO or picking a more efficient algorithm. Good reasons:

0) Back in the dark ages there was a limit of 63k of r-code per program. This was a way to reduce the size of r-code and stay under that limit (ok, that might not be a "good" reason). One additional way this helps is that you could also often avoid a DO ... END pair and further reduce r-code size.

1) When creating a record the fields that are part of an index will be written back to the database as they are assigned (not at the end of the transaction) -- grouping all assignments into a single statement helps to avoid inconsistent dirty reads. (This is probably the best reason to still do it.)

2) Readability -- you can argue that grouping consecutive assignments more clearly shows your intent and is thus more readable. (I like this reason but not everyone agrees.)




回答2:


ASSIGN will combine multiple statements into one. If a, v and w are fields in your db, that means it will do something like INSERT INTO (a,v,w)...

rather than INSERT INTO (a)... INSERT INTO (v)

etc.




回答3:


basically doing:

a=3.

v=7.

w=8.

is the same as:

assign a=3.

assign v=7.

assign w=8.

which is 3 separate statements so a little more overhead. Therefore less efficient.



来源:https://stackoverflow.com/questions/17109045/what-is-the-efficiency-of-an-assign-statement-in-progress-4gl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!