Skip to content

krishivsaini/Algorithm-Performance-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฌ Algorithm Performance Analyzer

A web-based application that empirically measures and visualizes the real-world execution time of classical algorithms across different input sizes. This project bridges the gap between theoretical time complexity (Big-O) and actual runtime behavior observed in practice.

License Node

๐Ÿ“‹ Table of Contents

๐ŸŽฏ Problem Statement

In academic settings, algorithms are often compared only using theoretical complexity. However, in real systems:

  • Constant factors matter - Two O(n log n) algorithms can have vastly different performance
  • Input size affects performance differently - Some algorithms excel with small inputs, others with large
  • Data distribution impacts behavior - Worst-case vs average-case scenarios differ significantly

This project allows users to observe and compare real execution time trends rather than relying solely on theory.

๐Ÿ’ก Solution Overview

The Algorithm Performance Analyzer provides:

  1. Empirical Benchmarking - Measure actual execution time, not just theoretical complexity
  2. Visual Comparison - See how algorithms scale with increasing input sizes
  3. Scientific Methodology - Multiple runs with averaging to reduce noise
  4. Educational Tool - Understand the gap between theory and practice

๐Ÿ—๏ธ System Architecture

The project follows a client-server architecture with clear separation of responsibilities:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 FRONTEND (React + Vite)                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  โ€ข React Components (modular UI)               โ”‚    โ”‚
โ”‚  โ”‚  โ€ข State Management (React Hooks)              โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Chart.js Visualization (react-chartjs-2)    โ”‚    โ”‚
โ”‚  โ”‚  โ€ข Vite Dev Server (HMR)                       โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚ HTTP Request (POST /api/benchmark)
                       โ”‚ { "algorithm": "quickSort" }
                       โ”‚
                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 BACKEND (Node.js + Express)             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  1. Receive algorithm selection                โ”‚    โ”‚
โ”‚  โ”‚  2. Generate test data (various sizes)         โ”‚    โ”‚
โ”‚  โ”‚  3. Run algorithm 5 times per size             โ”‚    โ”‚
โ”‚  โ”‚  4. Measure execution time (high-resolution)   โ”‚    โ”‚
โ”‚  โ”‚  5. Calculate averages                         โ”‚    โ”‚
โ”‚  โ”‚  6. Return structured results                  โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Frontend Responsibilities โœ…

  • Display algorithm selection UI
  • Send API requests to backend
  • Visualize results with interactive charts
  • Show performance data in tables

Frontend Does NOT โŒ

  • Run algorithms
  • Measure execution time
  • Perform heavy computation

Backend Responsibilities โœ…

  • Execute all algorithms
  • Generate test data
  • Measure execution time with precision
  • Calculate statistical averages
  • Ensure fair benchmarking conditions

โœจ Features

  • 5 Classic Algorithms: Bubble Sort, Merge Sort, Quick Sort, Linear Search, Binary Search
  • Multiple Input Sizes: Test with 100, 500, 1000, and 5000 elements
  • Statistical Accuracy: 5 runs per input size with averaging
  • Interactive Visualization: Beautiful charts showing performance trends
  • Detailed Results: Tabular data with exact timing measurements
  • Responsive Design: Works on desktop and mobile devices
  • Real-time Benchmarking: See results as they're computed

๐Ÿงฎ Algorithms Included

Algorithm Type Time Complexity Space Complexity
Bubble Sort Sorting O(nยฒ) O(1)
Merge Sort Sorting O(n log n) O(n)
Quick Sort Sorting O(n log n) avg, O(nยฒ) worst O(log n)
Linear Search Searching O(n) O(1)
Binary Search Searching O(log n) O(1)

๐Ÿš€ Installation

Prerequisites

  • Node.js >= 14.0.0
  • npm >= 6.0.0

Steps

  1. Clone the repository

    git clone https://github.com/krishivsaini/Algorithm-Performance-Analyzer.git
    cd Algorithm-Performance-Analyzer
  2. Install all dependencies

    npm run install:all

    This installs both backend and frontend (React) dependencies.

  3. Development mode (recommended)

    npm run dev

    This starts both:

  4. Production mode

    npm run build        # Build React app
    npm start            # Start backend (serves React build)
  5. Open your browser

๐Ÿ“– Usage

  1. Select an Algorithm

    • Open the application in your browser
    • Choose an algorithm from the dropdown menu
    • View the algorithm's complexity information
  2. Run Benchmark

    • Click the "Run Benchmark" button
    • Wait for the backend to complete the measurements (a few seconds)
    • The loading indicator shows progress
  3. Analyze Results

    • View the interactive line chart showing execution time vs input size
    • Check the detailed results table for exact timings
    • Compare the empirical results with theoretical complexity

๐Ÿ“ Project Structure

Algorithm-Performance-Analyzer/
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ algorithms/
โ”‚   โ”‚   โ”œโ”€โ”€ sorting.js          # Bubble, Merge, Quick Sort
โ”‚   โ”‚   โ””โ”€โ”€ searching.js        # Linear, Binary Search
โ”‚   โ”œโ”€โ”€ benchmark.js            # Benchmarking engine
โ”‚   client/                     # React + Vite frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Header.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ InfoSection.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ControlSection.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ LoadingIndicator.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ResultsSection.jsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Footer.jsx
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx             # Main React component
โ”‚   โ”‚   โ”œโ”€โ”€ main.jsx            # React entry point
โ”‚   โ”‚   โ””โ”€โ”€ index.css           # Global styles
โ”‚   โ”œโ”€โ”€ index.html              # HTML template
โ”‚   โ”œโ”€โ”€ vite.config.js          # Vite configuration
โ”‚   โ””โ”€โ”€ package.json            # Frontend dependencies
โ”‚
โ”œโ”€โ”€ package.json                # Root drontend logic and Chart.js
โ”‚
โ”œโ”€โ”€ package.json                # Dependencies and scripts
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿ”ฌ Benchmarking Methodology

Input Sizes

[100, 500, 1000, 5000]

Measurement Process

  1. Generate Fresh Data - Random array created for each run
  2. High-Resolution Timing - Uses performance.now() for microsecond precision
  3. Multiple Runs - Each algorithm runs 5 times per input size
  4. Statistical Averaging - Results averaged to reduce system noise
  5. Data Collection - Structured JSON response sent to frontend

Example Flow

For n = 1000:
  Run 1: 8.234 ms
  Run 2: 8.156 ms
  Run 3: 8.301 ms
  Run 4: 8.189 ms
  Run 5: 8.245 ms
  
Average: 8.225 ms โ†’ Reported Result

Why Averaging?

  • Reduces System Noise - Background processes, garbage collection
  • More Stable Results - Consistent, reproducible measurements
  • Realistic Performance - Reflects typical behavior, not edge cases

๐Ÿ“ก API Documentation

GET /api/algorithms

Returns list of available algorithms.

Response:

{
  "algorithms": [
    {
      "id": "bubbleSort",
      "name": "Bubble Sort",
      "complexity": "O(nยฒ)",
      "type": "sorting"
    },
    ...
  ]
}

POST /api/benchmark

Runs benchmark for specified algorithm.

Request:

{
  "algorithm": "quickSort"
}

Response:

{
  "algorithm": "quickSort",
  "results": [
    { "n": 100, "time": 0.8234 },
    { "n": 500, "time": 4.2156 },
    { "n": 1000, "time": 9.1023 },
    { "n": 5000, "time": 52.4567 }
  ]
}

GET /api/health

Health check endpoint.

Response:

{
  "status": "ok",
  "message": "Algorithm Performance Analyzer API is running"
}

๐Ÿ’ก Key Insights

This project demonstrates several important concepts:

  1. Theory vs Practice

    • Algorithms with the same Big-O can perform differently
    • Constant factors and implementation details matter
  2. Quick Sort vs Merge Sort

    • Quick Sort may be faster on average despite same O(n log n) complexity
    • Merge Sort provides more predictable, stable performance
  3. Scalability Observation

    • See exactly how algorithms scale with real data
    • Visualize the difference between O(n), O(n log n), and O(nยฒ)
  4. Real-World Performance

    • System factors affect benchmarks
    • Theoretical analysis alone is insufficient

โš ๏ธ Limitations

  • Memory Usage Not Measured - Currently only tracks execution time
  • Runtime Variability - Results influenced by JavaScript engine and system load
  • Single-Threaded - No parallel execution testing
  • Limited Algorithms - Only 5 classic algorithms currently included
  • Input Distribution - Only random data tested, not worst/best cases

๐Ÿ”ฎ Future Improvements

  • Memory Profiling - Track space complexity alongside time
  • More Algorithms - Graph algorithms, dynamic programming, etc.
  • Multiple Languages - Compare JavaScript vs Python vs C++
  • Best/Worst Case Testing - Pre-sorted, reverse-sorted inputs
  • CPU Isolation - More controlled benchmarking environment
  • Historical Comparison - Save and compare multiple benchmark runs
  • Algorithm Animation - Visualize how algorithms work
  • Custom Input - Allow users to provide their own test data

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ‘จโ€๐Ÿ’ป Author

Krishiv Saini


Built to demonstrate the difference between theoretical complexity and empirical performance. ๐Ÿš€

Releases

No releases published

Packages

No packages published