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

Comparison of Different Types of Global References

This test compares various ways to locate items that exist in a G2 knowledge base from inside a procedure. You find and bind global items, using these techniques:

To benchmark these statements, you can create 1000 instances of the test-object class. You assign an integer attribute running serially from 1 to 1000 to each object. You name the last item created (for the first test) and relate it to a permanent object (for the second test). The attribute value tests look for the test object whose integer attribute has the value 500.

Global Reference Microseconds
by name
1.6
by relation
22.0
by class/attribute value (explicit loop)
4200
by class/attribute value (not indexed)
4900
by class/attribute value (indexed)
43.0
by undirected connection
59.5
by directed connection
39.7
by connection with named port
41.1

Explicit searches for an object with a particular attribute value carry a very large cost, and implicit searches on non-indexed attributes via the if there exists ... such that statement. Indexed attribute value searches, on the other hand, are only a factor of 2.7 slower than searches based on relations. The time for the indexed attribute search is virtually unchanged when you increase the number of instances to 10,000. Searches based on connections are only between 1.7 and 2.6 times slower than searches based on relations.

Thus, the fastest way to reference an object based on a particular attribute value is by name. The next fasted way is to create a relation to the object. References to indexed attributes is somewhat slower than referencing by relation, but slightly faster than referencing by connection. If you are going to reference an object by connection, it is somewhat faster to use a directed connection or a connection with a named port. Finally, avoid direct references to objects with a particular attribute value via an explicit loop when the attribute is not indexed.

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

Copyright © 1997 Gensym Corporation, Inc.