Operation Tiers
Different operators have different performance costs. Here's what to expect.
| Tier | Operations | Overhead | Notes |
|---|---|---|---|
| 0 | +, -, scalar *, <<, ~ | ~200ns | Fastest. Use freely. |
| 1 | =, *, /, %, >>, &, |, ^ | ~8us | Needs recalculation. |
| 2 | ==, !=, <, >, <=, >= | ~0ns | Essentially free. |
Tier 0: ~200ns
The most common operations. Addition, subtraction, scalar multiplication, left shift, and bitwise NOT. These are extremely fast and can be used freely in any context, including tight loops.
Compuon<int> hp(100); Compuon<int> damage(25); Compuon<int> x(4); Compuon<int> flags(0x0F); hp -= damage; // ~200ns hp += Compuon<int>(10); // ~200ns x <<= 3; // ~200ns auto mask = ~flags; // integer-only
Tier 1: ~8us
Operations that require internal recalculation. Still fast enough for per-frame use — 100 Tier 1 ops = 0.8ms, which is 5% of a 60 FPS frame budget.
Compuon<int> hp(100); Compuon<int> other(2); Compuon<int> mask(0x3F); hp = 50; // assignment: ~8us hp *= other; // multiply: ~8us hp /= other; // division: ~8us hp %= Compuon<int>(10); // modulo: ~8us hp >>= 1; // right shift: ~8us hp &= mask; // bitwise AND/OR/XOR: ~8us
Tier 2: ~0ns
Comparisons are essentially free. Use them anywhere without concern.
Compuon<int> hp(100); Compuon<int> other(100); bool dead = hp <= Compuon<int>(0); // ~0ns bool same = hp == other; // ~0ns bool alive = hp > Compuon<int>(0); // ~0ns
Performance Guidelines
+Prefer Tier 0 ops in hot loops (damage calc, movement). ~200ns is negligible.
+Tier 1 ops are fine for per-frame use. Avoid in tight inner loops (thousands of iterations).
+Tier 2 comparisons are free — use them anywhere.
+Total overhead is typically <0.01% of frame time for normal game logic.