Socket
Book a DemoInstallSign in
Socket

ruby_native_statistics

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ruby_native_statistics

2.0.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

Ruby Native Statistics

Test status

This is a native extension to Ruby that adds native (Rust) statistical functions to the Array class. At present the following functions are provided:

Check the Github Actions build to see the currently supported versions of Ruby. This list will match whatever stable versions are specified at https://www.ruby-lang.org/en/downloads/.

It is generally more performant than calculating these values with pure Ruby. For a comparison, run the benchmarks with rake benchmark.

Here's the data converted to a Markdown table:

Benchmark (Ruby 3.4.4)Run 1Run 2Run 3Run 4Run 5
bench_ruby_median0.0006760.0006110.0006190.0006200.000583
bench_native_median0.0001790.0001670.0001270.0001180.000188
bench_ruby_stdev0.0007800.0007670.0007300.0007180.000733
bench_native_stdev0.0000460.0000270.0000340.0000260.000043
bench_ruby_mean0.0002610.0002400.0002420.0002500.000241
bench_native_mean0.0000330.0000230.0000220.0000280.000022

Found a bug? Need a function?

If you found a bug or need a particular function, please let me know! I work on this gem in my spare time, mainly for learning purposes. Feel free to open a PR or a Github issue and I'll take a look as soon as possible.

Usage

require 'ruby_native_statistics'
r = [1,3,21,32,42]

# calculate sample standard deviation, you can also use "stdevs"
p r.stdev

# calculate population standard deviation
p r.stdevp

# calculate sample variance
p r.var

# calculate population variance
p r.varp

# calculate mean
p r.mean

# calculate median
p r.median

# calculate percentile
p r.percentile(0.3333)

Build notes

If you are installing the source vesion of the Gem, be sure to have libclang, e.g. libclang-dev, installed on your system.

Implementation notes

Percentile

Percentile uses the same rounding method as Excel, sometimes called R7.

FAQs

Package last updated on 26 Jul 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.