| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 14)

Comparison of Various Types of References

This test compares various assignment statements to a local float variable (F), varying the right-hand side of the assignment as follows:

You can do two variable references in 28.8 microseconds, but you can do one variable reference followed by one local reference in only 16.9 microseconds. Thus, you should always assign a local variable whenever you are referencing the value of a variable more than once, because a G2 variable reference is more than five times slower than a local variable reference.

Referencing an attribute, parameter, or array, on the other hand, is only approximately twice as slow as referencing a local variable.

Also, referencing the elements of a list is a very slow operation compared to referencing the elements of an array. Thus, you should use arrays over lists whenever you need to reference an element by its index. The exception is referencing the first element of a list by its index, which is almost as fast as an array reference.

Referencing elements of sequences have similar performance as lists.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 14)

Copyright © 1997 Gensym Corporation, Inc.