Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests

on:
push:
branches: [main, developing]
branches: [main]
pull_request:
branches: [main, developing]
branches: [main]
workflow_dispatch:

permissions:
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# libcpprime

**libcpprime** is a efficient C++ implementation of a primality test optimized for 64-bit integers.
![badge](https://github.com/Rac75116/libcpprime/actions/workflows/tests.yml/badge.svg)

**libcpprime** is an efficient C++ implementation of a primality test optimized for 64-bit integers.

# Usage

Expand Down Expand Up @@ -92,6 +94,17 @@ This library is header-only, so you only need to specify the include path.
g++ -I ./libcpprime -O3 Main.cpp
```

# Benchmarks

The benchmark is run on GitHub Actions' Linux with gcc with -O3 optimization enabled.

You can find more detailed benchmark results by clicking [here](https://github.com/Rac75116/libcpprime/actions/workflows/bench.yml?query=branch%3Amain+is%3Acompleted).


![bench_IsPrime](bench_results/bench_IsPrime.jpg)
![bench_IsPrimeNoTable](bench_results/bench_IsPrimeNoTable.jpg)
![bench_summary](bench_results/bench_summary.jpg)

# Releases

- 2025/12/21 ver 1.3.0
Expand Down
Binary file added bench_results/bench_IsPrime.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench_results/bench_IsPrimeNoTable.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench_results/bench_summary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions benchmarks/isprime_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ int main(int argc, char** argv) {
std::ofstream f_summary("benchmarks/bench_summary.csv", std::ios::trunc);
std::ofstream f_summary_md("benchmarks/bench_summary.md", std::ios::trunc);
f_summary << "avg_time_prime_IsPrime,avg_time_prime_IsPrimeNoTable,avg_time_composite_IsPrime,avg_time_composite_IsPrimeNoTable\n";
f_summary_md << "| Bit Width | IsPrime Avg Time (ns) | IsPrimeNoTable Avg Time (ns) | IsPrime Avg Time (ns) | IsPrimeNoTable Avg Time (ns) |\n";
f_summary_md << "|-----------|-----------------------|------------------------------|-----------------------|------------------------------|\n";
f_summary_md << "| Bit Width | IsPrime Avg Time (ns, prime) | IsPrimeNoTable Avg Time (ns, prime) | IsPrime Avg Time (ns, composite) | IsPrimeNoTable Avg Time (ns, composite) |\n";
f_summary_md << "|-----------|------------------------------|-------------------------------------|----------------------------------|-----------------------------------------|\n";
for (std::int32_t i = 1; i <= 64; ++i) {
std::string avg_prime = count_prime[i] ? std::to_string(time_prime_sum[i] / count_prime[i]) : "nan";
std::string avg_prime_NoTable = count_prime_NoTable[i] ? std::to_string(time_prime_sum_NoTable[i] / count_prime_NoTable[i]) : "nan";
Expand Down
4 changes: 2 additions & 2 deletions tests/isprime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ TYPED_TEST(IsPrimeTest, Fermat) {
}

std::vector<std::uint64_t> ReadFile(const std::string& filepath, bool expected_result) {
std::string currect_file = __FILE__;
std::string dir = currect_file.substr(0, currect_file.find_last_of("/\\"));
std::string current_file = __FILE__;
std::string dir = current_file.substr(0, current_file.find_last_of("/\\"));
std::string full_path = dir + "/" + (expected_result ? "primes" : "composites") + "/" + filepath;
std::vector<std::uint64_t> numbers;
std::ifstream file(full_path);
Expand Down