diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d176c01..18dc417 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,9 +2,9 @@ name: Tests on: push: - branches: [main, developing] + branches: [main] pull_request: - branches: [main, developing] + branches: [main] workflow_dispatch: permissions: diff --git a/README.md b/README.md index aa887c1..431c0b8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/bench_results/bench_IsPrime.jpg b/bench_results/bench_IsPrime.jpg new file mode 100644 index 0000000..aedc262 Binary files /dev/null and b/bench_results/bench_IsPrime.jpg differ diff --git a/bench_results/bench_IsPrimeNoTable.jpg b/bench_results/bench_IsPrimeNoTable.jpg new file mode 100644 index 0000000..922c1ac Binary files /dev/null and b/bench_results/bench_IsPrimeNoTable.jpg differ diff --git a/bench_results/bench_summary.jpg b/bench_results/bench_summary.jpg new file mode 100644 index 0000000..8526a28 Binary files /dev/null and b/bench_results/bench_summary.jpg differ diff --git a/benchmarks/isprime_bench.cpp b/benchmarks/isprime_bench.cpp index 062c8d4..eb05065 100644 --- a/benchmarks/isprime_bench.cpp +++ b/benchmarks/isprime_bench.cpp @@ -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"; diff --git a/tests/isprime_tests.cpp b/tests/isprime_tests.cpp index fa1b8a8..aef8259 100644 --- a/tests/isprime_tests.cpp +++ b/tests/isprime_tests.cpp @@ -107,8 +107,8 @@ TYPED_TEST(IsPrimeTest, Fermat) { } std::vector 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 numbers; std::ifstream file(full_path);