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

Comparing G2 Operations

This chapter presents some specific data on the relative efficiency of certain G2 statements, expressions, and operations. This data supports the recommendations provided in Chapter 10, Maximizing Performance.

This information might be helpful in designing data structures that maximize the efficiency of your application. For example, if you are considering the trade-offs between storing data in an array or as an attribute of an object, knowing that the conclude action takes about five times as long as the change action might help you make the best decision. However, bear in mind that you should rarely base design decisions solely on the basis of performance, and you should never overlook the importance of clarity and maintainability of your code.

The following data were collected using G2 5.0 Rev. 1, under Windows NT, running on an Intel 200Mhz Pentium Pro CPU processor.


Caution: G2 internal implementation is subject to change without notice, and future improvements might affect the relative efficiency of G2 actions. Information given here is approximate and applies only to the stated version of G2 on the given platform. The results for different platforms and future versions of G2 might vary.

Example of Comparing Operations: Change Versus Conclude

To compare the efficiency of two types of statements accurately, you can create procedures that run the target statement repeatedly to accumulate a significant amount of elapsed time, usually one or more seconds. For example, to compare the performance of the change action to that of the conclude action, you can profile the following procedures, using the same value of N:

For N = 50,000, the results are:

You calculate the efficiency of a single change or conclude action by removing the time taken for the empty loop, dividing by the number of iterations, and multiplying by 106 to get the number of microseconds:

Concluding a value takes more than seven times longer than changing a value. Thus, you should use the change action over the conclude action whenever possible.

The time for creating the test object and setting up the array is negligible and can be ignored.


Note: It is not unusual for the results of a specific benchmark to vary up to 20% due to profiling inaccuracies.

Even in such a simple example, many details might affect the results of the test. For example:

Thus, before reading too much into the results, it is important have the details of the benchmark.

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

Copyright © 1997 Gensym Corporation, Inc.