Anual Pague anualmente e ganhe 2 meses grátis em qualquer plano pago. Ver planos
Entrar Comece grátis

Revisão de performance

Entrada
Código
function add(a, b) { return a + b; }
Resultado de exemplo Criado em 27 outubro 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 size O(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) remains O(1)), but it may avoid O(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.
Usar isto Revisão de performance O formulário abre preenchido com as entradas deste exemplo; altere o que quiser.