A small C project to explore compiler optimizations by building and comparing different optimization levels (e.g., -O0 vs -O3) and their outputs. The repository includes source code, build rules, test script(s), prebuilt reference binaries, and logs to help validate behavior across optimization settings.
- Overview
- Repository layout
- Build
- Run
- Testing and validation
- Artifacts and logs
- Development notes
- License
This project centers around copt.c, a C program intended to be compiled under different optimization flags and then executed to observe behavioral and performance differences. You can build locally using the provided Makefile, run the resulting binaries, and compare outputs to reference binaries. A PDF (copt.pdf) appears to provide report or documentation about the project.
- copt.c — Main C source file.
- Makefile — Build rules to compile the project.
- test_orig.sh — Test script to run the binaries and collect outputs/logs.
- copt.pdf — Report or documentation PDF for the project.
- ._copt.pdf — Auxiliary/metadata file (may be an artifact from macOS Finder).
- copt_O0 — Prebuilt binary compiled with
-O0. - copt_O3 — Prebuilt binary compiled with
-O3. - copt_O0_ref — Reference binary for
-O0. - copt_O3_ref — Reference binary for
-O3. - mine_O0.log — Log from running your
-O0build. - mine_O3.log — Log from running your
-O3build. - ref_O0.log — Log from running the reference
-O0binary. - ref_O3.log — Log from running the reference
-O3binary. - .gitattributes — Git attributes configuration.
Requirements:
- GCC (or compatible C compiler)
- Make
Build steps:
- Clone the repository:
git clone https://github.com/dhrumilp12/copt.git cd copt - Use the
Makefileto build:This should produce binaries for different optimization levels (e.g.,make
copt_O0,copt_O3). If your environment requires specific flags or targets, inspect and adjust theMakefileaccordingly.
Manual build (example):
# Build with no optimizations
gcc -O0 -o copt_O0 copt.c
# Build with aggressive optimizations
gcc -O3 -o copt_O3 copt.cExecute the binaries directly:
./copt_O0
./copt_O3If your program expects input arguments or reads from stdin, pass them as needed. Refer to copt.c for the exact interface if unsure.
Use the provided script to run and compare outputs:
bash test_orig.shThe script is expected to:
- Run your built binaries (
copt_O0,copt_O3) - Optionally run the reference binaries (
copt_O0_ref,copt_O3_ref) - Capture outputs to log files for comparison
After running, check the generated or updated logs:
- mine_O0.log vs ref_O0.log
- mine_O3.log vs ref_O3.log
A simple diff can help verify equivalence:
diff -u ref_O0.log mine_O0.log
diff -u ref_O3.log mine_O3.logPrebuilt/reference binaries:
copt_O0,copt_O3— Current builds (or example artifacts)copt_O0_ref,copt_O3_ref— Reference builds to compare against
Logs:
mine_O0.log,mine_O3.log— Output from your local buildsref_O0.log,ref_O3.log— Output from reference binaries
If outputs differ, investigate:
- Compiler version differences
- Undefined behavior in code that optimization may expose
- Platform-specific behavior (e.g., floating-point, library versions)
- Primary code changes happen in
copt.c. - If adding new tests or inputs, consider updating
test_orig.shto automate runs and log generation. - Keep
Makefiletargets consistent for reproducible optimization comparisons.
No explicit license file is present. If you intend others to use or modify this project, consider adding a LICENSE file (e.g., MIT, Apache-2.0, GPL-3.0) to clarify terms.
For questions or improvements, open an issue or PR. Refer to copt.pdf for background or detailed write-up if applicable.