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 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.


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

$ codeboost --sophus --user-rules -l Vector.h >

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


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

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.


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

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.


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

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%
mutify 5.06s 2.35 57.4%
map 5.14s 2.31 56.7%
map fusion 3.04s 3.91 74.4%

Vector Size: 100000 elements

transformation time improvement factor time reduction output code
stubs 217.3s 1.00 0.0%
mutify 157.7s 1.38 27.4%
map 157.7s 1.38 27.5%
map fusion 32.0s 6.79 85.3%

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