Skip to content

Compare language speeds using a simple sieve of Eratosthenes benchmark

modiase/sievebench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Language Sieve of Eratosthenes Benchmark

This project implements a parallelized Sieve of Eratosthenes algorithm in Go, C++, and Rust to find all prime numbers up to a given integer 10^N.

Prerequisites

This project uses the Nix package manager to provide a consistent development environment with all the necessary compilers and build tools.

Building and Running Manually

You can build and run each language's implementation individually. Replace 9 with the desired upper limit (N).

Go

sh cd sieve_go go run . 9

To build an optimized executable:

C++

The C++ version uses the Meson build system.

  1. Configure the build (only needs to be done once):

    sh cd sieve_cpp meson setup builddir

  2. Compile the code:

    sh cd sieve_cpp meson compile -C builddir

  3. Run the executable: sh ./sieve_cpp/builddir/sieve_cpp 9

Fortran

The Fortran version also uses Meson.

  1. Configure the build (only needs to be done once):

    sh cd sieve_fortran meson setup builddir

  2. Compile the code:

    sh cd sieve_fortran meson compile -C builddir

  3. Run the executable: sh ./sieve_fortran/builddir/sieve_fortran 9

Rust

The Rust version uses Cargo.

  1. Build the optimized executable:

    sh cd sieve_rust cargo build --release

  2. Run the executable: sh ./sieve_rust/target/release/sieve_rust 9

Running the Benchmark

The benchmark script in the root of the project will automatically build and run all implementations, executing each one multiple times to provide stable performance metrics. It uses hyperfine for benchmarking and runs within a consistent Nix development environment.

To run the full benchmark suite:

sh ./benchmark

To see the output from the build commands, use the -v (verbose) flag:

sh ./benchmark -v

About

Compare language speeds using a simple sieve of Eratosthenes benchmark

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published