Vector Example

The Vector class is a simple array-like class with elementwise overloaded operators. The operators are implemented as Sophus-style updating operators, and as user-defined rules using a map pattern. This example is included in the examples/ subdirectory of the CodeBoost distribution.

The file vector.cc creates a few Vector objects, and performs operations on them. One of the following four transformations can be used to make the code compilable:

Stub generation:
No optimisation is performed. Non-updating stub operators are generated as wrappers for the updating operators.

Command-line:

$ codeboost -sophus-stubs -user-rules Vector.h > Vector-boost.h

$ codeboost --sophus --user-rules -l Vector.h vector.cc > vector-stub.cc

Mutification:
Calls to non-updating operators are rewritten as calls to updating operators. Much better performance than using non-updating operators directly.

Command-line:

$ codeboost --sophus --user-rules -l Vector.h -t mutify vector.cc > vector-mutify.cc

Map pattern instantiation:
User-defined rules are used to replace operator calls with calls to the mapcs function. Instantiations of mapcs are then inlined at the call site.

Command-line:

$ codeboost --sophus --user-rules -l Vector.h -t apply-user-rules apply-user-rules='--no-bottomupr' -t mutify -t inline vector.cc > vector-map.cc

Map fusion:
The mapcs-based operator implementations are used. Multiple nested mapcs calls are then fused into a single call, which is instantiated and inlined.

Command-line:

$ codeboost --sophus --user-rules -l Vector.h -t apply-user-rules -t compose -t mutify -t inline vector.cc > vector-mapfusion.cc

Performance Measurements

Measurements were taken on an AMD Athlon XP 2200+ running Linux 2.4.20. Compiled with -O, using GCC 3.2.

Vector Size: 10000 elements

transformation time improvement factor time reduction output code
stubs 11.88s 1.00 0.0% vector-stub.cc
mutify 5.06s 2.35 57.4% vector-mutify.cc
map 5.14s 2.31 56.7% vector-map.cc
map fusion 3.04s 3.91 74.4% vector-mapfusion.cc

Vector Size: 100000 elements

transformation time improvement factor time reduction output code
stubs 217.3s 1.00 0.0% vector-stub.cc
mutify 157.7s 1.38 27.4% vector-mutify.cc
map 157.7s 1.38 27.5% vector-map.cc
map fusion 32.0s 6.79 85.3% vector-mapfusion.cc


Maintained by Otto Skrove Bagge. Last updated May 9, 2003.