Skip to main content

Bun

info

Versao: Bun 1.x Rootfs: 500 MB Tipo: Runtime

Overview

Bun e um runtime JavaScript all-in-one extremamente rapido. Inclui bundler, transpiler, package manager e test runner em um unico executavel.

Especificacoes

PropriedadeValor
Versao1.x
Comandobun run
Extensao.js / .ts
Rootfs Size500 MB
Tempo de Execucao~100ms

Por que Bun e Rapido?

  • Escrito em Zig (linguagem de baixo nivel)
  • Motor JavaScript JSC (Safari) ao inves de V8
  • Otimizado para startup time
  • APIs nativas implementadas em Zig

Exemplos

Hello World

Simple console output
console.log("Hello World");

TypeScript Nativo

TypeScript with type annotations
const greet = (name: string): string => {
return `Hello, ${name}!`;
};

console.log(greet("Bun"));

Arrays e Objetos

Array map and reduce operations
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
const sum = numbers.reduce((a, b) => a + b);

console.log("Doubled:", doubled);
console.log("Sum:", sum);

Classes

Class with static properties
class Calculator {
add(a, b) { return a + b; }
multiply(a, b) { return a * b; }

static pi = 3.14159;
}

const calc = new Calculator();
console.log(calc.add(2, 3));
console.log(calc.multiply(4, 5));
console.log(Calculator.pi);

Async/Await

Async/await with delay
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

async function main() {
console.log("Starting...");
await delay(100);
console.log("Done!");
}

main();

Comparacao de Performance

RuntimeStartupHello World
Bun~10ms~50ms
Node.js~30ms~100ms
Deno~25ms~80ms

Limitacoes

  • Sem acesso a rede
  • Sem acesso a sistema de arquivos
  • Timeout padrao de 10 segundos
  • Memoria limitada a 512MB
  • Algumas APIs Node.js nao implementadas