Git Product home page Git Product logo

primegen's Introduction

primegen

C++ CI

  • primegen.hpp: C++ header-only library to generate small primes using Sieve of Eratosthenes
  • primegen.cpp: Command line utility

Goal

The goal of this project is not to be the fastest prime sieve. If you're looking for something like that then try https://github.com/kimwalisch/primesieve instead. The goal of this project is to be a fast prime sieve that can easily be included in C++ projects.

Getting started

git clone https://github.com/cr-marcstevens/primegen
cd primegen
make
make check
./primegen 512     # print primes <= 512
./primegen 256 512 # print primes >= 256, <= 512

Robustness

Various tests have been done to verify correctness:

  • check first 1'000'000'000 primes against known good prime generator
  • verify number of primes <= N against wolfram alpha, for N up to 3435973836800 (~2^41.6)
  • verify sum of primes <= N against wolfram alpha, for N up to 2^33

Memory usage

primegen generate primes up to a given upper-bound U to which it will sieve. It will use approximately U/16 bytes of RAM. TODO: implement segmented version that will use constant*sqrt(U) memory.

Speed

Performance will vary with CPU. But here are some performance numbers for an Intel i7-7567U:

# sums all primes up to 2^32 in 4.3s
time ./primegen $((1<<32)) -s

# prints all primes up to 2^32 in decimal in 8.4s
time ./primegen $((1<<32)) > /dev/null

# sums all primes up to 2^38 in 6m50s
time ./primegen $((1<<38)) -s

# prints all primes up to 2^38 in decimal in 10m35
time ./primegen $((1<<38)) > /dev/null

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.