Build into dist/, list primes to 1,000,000 with timing, add wiki

This commit is contained in:
2026-10-20 01:07:36 +08:00
parent e4be228a5b
commit 42774d3d3a
8 changed files with 173 additions and 70 deletions
+24
View File
@@ -0,0 +1,24 @@
# Build and run
**English**
The `Makefile` is in the repository root and puts the executable in `dist/`.
It needs `gcc` (Linux, or MinGW-w64 / MSYS2 on Windows) and a CPU with AVX2.
```bash
make
```
```bash
make run
```
```bash
make clean
```
To save the primes and still see the time, redirect only standard output:
```bash
./dist/prime_avx2 > primes.txt
```
+34
View File
@@ -0,0 +1,34 @@
# Description
**English**
## Purpose
The program shows how fast a CPU is. How fast it looks depends on how the
program is written, so the number is a measure of the CPU and the code
together, not of the CPU alone.
## What it does
It tests every number from 0 to 1,000,000 with `is_prime_avx2`, which uses
AVX2 trial division by 6k ± 1 (four divisors per step). It prints each prime
on its own line and writes a summary line to standard error:
```text
Found 78498 primes from 0 to 1000000 in 13.806 ms
```
78,498 is the known count of primes up to 1,000,000, so the summary line also
works as a correctness check.
## Why the time depends on the code
The same CPU gives very different times for different programs:
- the algorithm (trial division, a sieve, a segmented sieve),
- the instruction set used (scalar code, AVX2, AVX-512),
- compiler and flags (`-O3 -mavx2`, MSVC `/O2 /arch:AVX2`),
- what is measured (only the search, or also printing to a console).
Here only the search is timed. Output is collected first and printed
afterwards, so console speed does not change the number.
+10
View File
@@ -0,0 +1,10 @@
# prime-numbers-c
**English**
A small C program that lists every prime number from 0 to 1,000,000 and
reports how long it took.
- [Description](Description): what the program is for
- [Results](Results): measured times on real hardware
- [Build and run](Build-and-Run): `make`, `make run`
+14
View File
@@ -0,0 +1,14 @@
# Results
**English**
Time to find all primes from 0 to 1,000,000. Only the search is timed.
| CPU | Result |
| --- | --- |
| 13th Gen Intel(R) Core(TM) i5-13600K | Found 78498 primes from 0 to 1000000 in 20.977 ms |
A result is only comparable with another when the code, compiler and flags
are the same. To add a result, run the program on your machine (see
[Build and run](Build-and-Run)) and add a row with your CPU name and the
summary line.
+4
View File
@@ -0,0 +1,4 @@
- [Home](Home)
- [Description](Description)
- [Results](Results)
- [Build and run](Build-and-Run)