DEV Community

Cover image for ⚡Mencoba Komparasi Seberapa Kencang Performa Bun dibandingkan Node
Ferry Ananda Febian
Ferry Ananda Febian

Posted on

3 1 1 1 1

⚡Mencoba Komparasi Seberapa Kencang Performa Bun dibandingkan Node

Sudah lumayan lama sejak terakhir kali nerbitin artikel di platform ini, kemarin ane nerbitin ini 🚀Cara Mudah Ganti Akun Github di Windows

Jadi sekarang ane mau coba bandingkan performa Bun dan Node, Bun dan Node ini sama-sama runtime nya JavaScript ya, bedanya Bun ini juga bisa digunakan sebagai package manager juga, berbeda dengan Node yang masih membutuhkan package manager lain seperti npm, yarn, pnpm. Jadi seberapa kencang sih Bun ini?

Untuk persiapan yang ane lakukan yaitu dengan mengukur waktu eksekusi dari sebuah fungsi yang ane buat dengan tingkat kompleksitas yang berbeda-beda,

untuk lebih jelasnya silahkan lihat source code dibawah ini:

function testFunction(complexity = 1000000) {
  let result = 0;
  for (let i = 0; i < complexity; i++) {
    result += Math.sqrt(i) + Math.sin(i) + Math.cos(i);
  }
  return result;
}

function measureExecutionTime(func, ...args) {
  const start = performance.now();
  const result = func(...args);
  const end = performance.now();
  return { executionTime: end - start, result };
}

function runBenchmark(iterations = 5) {
  const complexities = [100000, 500000, 1000000, 2000000];

  complexities.forEach((complexity) => {
    console.log(`\nBenchmark untuk kompleksitas: ${complexity}`);
    let totalTime = 0;

    for (let i = 0; i < iterations; i++) {
      const { executionTime, result } = measureExecutionTime(testFunction, complexity);
      totalTime += executionTime;
      console.log(`Iterasi ${i + 1}: ${executionTime.toFixed(2)} ms, Hasil: ${result.toFixed(2)}`);
    }

    const averageTime = totalTime / iterations;
    console.log(`Rata-rata waktu eksekusi: ${averageTime.toFixed(2)} ms`);
  });
}

runBenchmark();
Enter fullscreen mode Exit fullscreen mode

Untuk spesifikasi teknis lainnya sebagai berikut:

  • CPU: AMD Ryzen 5 7640HS
  • RAM: 16GB
  • OS: Windows 11
  • Node: 20.12.0
  • Bun: 1.0.13

Hasil dari percobaan diatas adalah sebagai berikut:

Kompleksitas Runtime Iterasi 1 (ms) Iterasi 2 (ms) Iterasi 3 (ms) Iterasi 4 (ms) Iterasi 5 (ms) Rata-rata (ms)
100000 Node.js 11.83 8.24 2.49 2.35 2.34 5.45
Bun 5.81 2.39 2.37 2.39 2.51 3.09
500000 Node.js 13.28 13.99 13.52 13.15 13.95 13.58
Bun 12.13 12.85 12.91 12.99 12.78 12.73
1000000 Node.js 26.59 26.22 28.28 25.90 26.10 26.62
Bun 25.16 24.21 24.86 24.47 25.79 24.90
2000000 Node.js 137.59 136.67 141.01 138.89 138.92 138.62
Bun 49.12 48.72 50.54 50.84 49.35 49.71

Dari hasil diatas dapat dilihat bahwa Bun ini memang lebih cepat dari Node.js, terutama untuk kompleksitas yang lebih tinggi, Bun ini membutuhkan waktu rata-rata sekitar 1/4 dari Node.js.

Jadi gimana menurut agan? apakah berminat untuk mencoba Bun?

Sekian dari ane, terima kasih.

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (1)

Collapse
 
ferryops profile image
Ferry Ananda Febian

reserved()

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay