Voorbeelduitvoer
Gemaakt op 27 oktober 2026
Performance review
Hot path complexity
- Time:
O(1)per call. - Space:
O(1). - There are no loops, recursive calls, or input-dependent operations.
Allocation / GC pressure
- For numeric inputs, the function typically creates no heap allocations, so GC pressure is negligible.
- If either operand is a string,
+performs concatenation and allocates a new string of sizeO(len(a) + len(b)). - Untyped parameters allow mixed operand types, which may introduce coercion and reduce JIT optimization stability at polymorphic call sites.
I/O / N+1 patterns
- No I/O, network, database, filesystem, or N+1 behavior.
Optimized version
function add(a: number, b: number): number {
return a + b;
}
Change notes
- Added numeric parameter and return types: prevents accidental string concatenation and mixed-type usage; can keep hot call sites monomorphic. Expected algorithmic improvement: none (
O(1)remainsO(1)), but it may avoidO(len(a) + len(b))string allocation and coercion when callers pass incorrect types. - Kept the implementation direct: function-call overhead may be inlined by modern JavaScript engines. Further micro-optimization is unlikely to provide a measurable win in normal workloads.
- GC impact: remains effectively zero for numeric inputs.