Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

median-quickselect

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

median-quickselect

Fast implementation of median search using quickselect algorithm

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
increased by10.34%
Maintainers
1
Weekly downloads
 
Created
Source

median-quickselect

NPM

Fast implementation of lower median search using Quick select algorithm. Ported from this C implementation.

Please read "Fast median search: an ANSI C implementation" by Nicolas Devillard for more info.

Note that result can be different from other packages, as median-quickselect calculates lower median, because taking an average of the two central elements requires two calls to the routine, doubling the processing time.

Installation

Install from npm:

npm install --save median-quickselect

Or hot-link via unpkg.com

<script src="https://unpkg.com/median-quickselect"></script>

Usage

const median = require('median-quickselect');
median([1, 4, 10, 2, 5, 0, -5]); // 2

Note that the **order of elements ** on array passed to median() will be changed after call.

Benchmark

$ npm run bench                                                                                                                                                                       1001 ms  master 

> node test/benchmark.js

benchmarking dataset of 100 numbers
median: 0.891ms
fast-median: 0.999ms
compute-median: 0.269ms
stats-median: 0.159ms
median-quickselect: 0.230ms

benchmarking dataset of 1000 numbers
median: 0.849ms
fast-median: 1.713ms
compute-median: 0.562ms
stats-median: 0.210ms
median-quickselect: 0.204ms

benchmarking dataset of 10000 numbers
median: 6.249ms
fast-median: 9.413ms
compute-median: 5.816ms
stats-median: 5.101ms
median-quickselect: 2.027ms

benchmarking dataset of 1000000 numbers
median: 576.688ms
fast-median: 886.843ms
compute-median: 786.714ms
stats-median: 662.177ms
median-quickselect: 13.027ms

benchmarking dataset of 10000000 numbers
median: 6347.193ms
fast-median: 8722.377ms
compute-median: 7278.490ms
stats-median: 7089.452ms
median-quickselect: 119.298ms

Keywords

FAQs

Package last updated on 27 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc