百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

primesieve

> 测试质量
开源

快速素数生成器

1.1K stars0 点赞4 次浏览
访问官网GitHub

工具介绍

快速素数生成器

primesieve

primesieve is a command-line program and C/C++ library for quickly generating prime numbers. It is very cache efficient, it detects your CPU's L1 & L2 cache sizes and allocates its main data structures accordingly. It is also multi-threaded by default, it uses all available CPU cores whenever possible i.e. if sequential ordering is not required. primesieve can generate primes and prime k-tuplets up to 264.

primesieve generates primes using the segmented sieve of Eratosthenes with wheel factorization. This algorithm has a run time complexity of $O(n\ \log\ \log\ n)$ operations and uses $O(\sqrt{n})$ memory. Furthermore primesieve uses the bucket sieve algorithm which improves the cache efficiency when generating primes > 232. primesieve uses 8 bytes per sieving prime, in practice its memory usage is about $\pi(\sqrt{n})\times 8$ bytes per thread.

  • More algorithm details

Installation

The primesieve command-line program can be installed using your operating system's package manager. For doing development with libprimesieve you may need to install libprimesieve-dev or libprimesieve-devel.

    Windows:
    winget install primesieve




    macOS:
    brew install primesieve




    Arch Linux:
    sudo pacman -S primesieve




    Debian/Ubuntu:
    sudo apt install primesieve




    Fedora:
    sudo dnf install primesieve




    FreeBSD:
    pkg install primesieve




    openSUSE:
    sudo zypper install primesieve

Usage examples

# Count the primes ≤ 1e10 using all CPU cores
primesieve 1e10

# Print the primes ≤ 1000000
primesieve 1000000 --print

# Store the primes ≤ 1000000 in a text file
primesieve 1000000 --print > primes.txt

# Print the twin primes ≤ 1000000
primesieve 1000000 --print=2

# Count the prime triplets inside [1e10, 1e10+2^32]
primesieve 1e10 --dist=2^32 --count=3

Note that printing primes and storing them in a text file are not primesieve's primary use cases: both run single-threaded as printing requires sequential ordering, and both use the same standard output path rather than file-specific I/O optimizations. For maximum throughput, generate primes in memory using libprimesieve.

Stress testing

primesieve includes support for stress testing both the CPU and memory. This feature is useful for checking system stability under maximum load and verifying whether your cooling solution (fans, heatsinks, thermal paste, etc.) is adequate. primesieve's stress test supports two modes: CPU (highest CPU load, uses little memory) and RAM (high memory usage, uses about 1.2 GiB per thread).

…

Command-line options

Usage: primesieve [START] STOP [OPTION]...
Generate the primes and/or prime k-tuplets inside [START, STOP]
( 100.
  -p, --print[=NUM]          Print primes or prime k-tuplets, NUM 

int main()
{
  primesieve_iterator it;
  primesieve_init(&it);
  uint64_t prime;

  /* Iterate over the primes < 10^6 */
  while ((prime = primesieve_next_prime(&it)) < 1000000)
    printf("%" PRIu64 "\n", prime);

  primesieve_free_iterator(&it);
  return 0;
}
  • C API documentation

C++ API

Include the `````` header to use libprimesieve's C++ API.

#include 
#include 

int main()
{
  primesieve::iterator it;
  uint64_t prime = it.next_prime();

  // Iterate over the primes < 10^6
  for (; prime < 1000000; prime = it.next_prime())
    std::cout << prime << std::endl;

  return 0;
}
  • C++ API documentation

Bindings for other languages

primesieve natively supports C and C++ and has bindings available for:

    Common Lisp:
    cl-primesieve




    Java:
    primesieve-java




    Janet:
    janet-primesieve




    Julia:
    PrimeSieve.jl




    Lua:
    lua-primesieve




    Nim:
    primesievec-nim




    Haskell:
    primesieve-haskell




    Pascal:
    primesieve-pas




    Perl:
    Primesieve




    Python:
    primesieve-python




    Raku:
    raku-primesieve




    Ruby:
    primesieve-ruby




    Rust:
    primesieve.rs

Many thanks to the developers of these bindings!

Sponsors

Thanks to all current and past sponsors of primesieve! Your donations help me purchase (or rent) the latest CPUs and ensure primesieve runs at maximum performance on them. Your donations also motivate me to continue maintaining primesieve.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++arm-neonarm-sveavx512benchmark

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类测试质量
定价开源

> 相关工具

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.