npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sorting-benchmark

v1.0.1

Published

A sorting algorithm benchmark tool

Downloads

115

Readme

Sort Algorithm Comparator (BETA)

This project provides two main features to help developers evaluate and benchmark sorting algorithms in JavaScript.


TL;DR

  1. add import('sorting-benchmark') to the file that you wanna analyze
  2. check ~/.js-sorting-logs/times.log file to see results

Feature 1: Enhanced Array Sorting

Once the project is integrated into your environment, it modifies the behavior of the native Array.prototype.sort() method. Instead of using the default sorting algorithm, your arrays will be sorted using various algorithms. The time taken for each algorithm will be logged into ~/.js-sorting-logs/times.log, allowing you to track the performance and determine the most efficient algorithm for your use case.

Feature 2: Benchmarking Sorting Algorithms

You can also benchmark multiple algorithms using either predefined or randomly generated datasets.

Data Structure

The data for benchmarking is stored in data.json. Each array object contains two arrays (e.g., firstArray and secondArray). The arrays are compared pairwise, where the first element of firstArray is compared with the first element of secondArray, and so on. Both arrays must have the same length, and each object requires a key.

Example:

{
  "firstArray": [
    [1, 2, 3],
    [4, 5, 6]
  ],
  "secondArray": [
    [1, 3, 2],
    [6, 5, 4]
  ]
}

Generating Test Data

To generate random datasets for testing, use:

npm run generateData

This will populate data.json with ordered, mostly ordered, and random datasets, preparing your project for benchmarking.

Running Benchmarks

Once the data is ready, run:

npm run benchmark

This will compare multiple sorting algorithms, running each algorithm 20 times (by default) on every array. The benchmark calculates the average execution time and displays the results in the terminal.

Known Bugs/Errors

  1. Only works with numbers. Every custom sorting algorithm sorting strings differently. Send me an email if you wanna help about that topic.

TODO List

  • [ ] Add repeat into cli parameters --repeat=20
  • [ ] Add data into cli parameters --data=path/to/customData.json
  • [ ] Select algorithms to run --allow=quicksort,timsort
  • [ ] Select algorithms to disable --disable=quicksort,timsort
  • [ ] Filter max best case complexity --bc=on2
  • [ ] Filter max worst case complexity --wc=logn
  • [ ] Filter max average case complexity --ac=on
  • [ ] Select output file type --output=json
  • [ ] Add memory usages into log --with-memory
  • [ ] Filter minimum array length --minLength=100
  • [ ] Filter maximum array length --minLength=10000
  • [ ] Allow adjusting the log file location --log=path/to/logs
  • [ ] Add visual graphs for benchmarking results