2.0.0 • Published 8 months ago
prime-number v2.0.0
prime-number
check if a number is prime
Is it 1 a prime? Some years ago I created a djembe rhythm generated by prime numbers, and it sounds good if 1 is considered prime. However, the algorithm implemented here defines 1 as a not prime.
Installation
With npm do
npm install prime-numberUsage
As you might expect, you can simply do
import isPrime from 'prime-number'
console.log(isPrime(19)) // trueYou can also use CommonJS.
const isPrime = require('prime-number')Benchmarks
Clone this repo and install packages for benchmarks with --no-save flag.
npm install check-prime is-prime --no-saveThen run benchmark scripts.
Using this prime-number package.
npm run benchmark:prime-number
Found 8363 primes
Primality benchmark: 7.064msUsing is-prime package.
npm run benchmark:is-prime
Found 8363 primes
Primality benchmark: 7.045msUsing check-prime package.
npm run benchmark:check-prime
Found 8363 primes
Primality benchmark: 23.785ms