HW3 Experiment Protocol (shared spec for every language implementation)
Source assignment: HW3.docx ("CSC 482 Homework 3 - Language Comparison", 15 pts).
Unit reading tie-in: CLRS Chapter 5, "Probabilistic Analysis and Randomized Algorithms"
(hiring problem, indicator random variables, randomized quicksort).
Algorithm
Randomized Quicksort, following CLRS's RANDOMIZED-QUICKSORT / RANDOMIZED-PARTITION:
in-place quicksort where, at every partition step, the pivot is chosen uniformly at
random from the current subarray range and swapped into the last position before
running the standard Lomuto (or Hoare) partition. Expected running time O(n log n).
Cite this design as: Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms,
Ch. 5, RANDOMIZED-QUICKSORT/RANDOMIZED-PARTITION pseudocode — implementation is
original code in each language, not copied from any online source, unless a language's
report says otherwise (any borrowed snippet must be cited with its URL/source).
Only language standard library / standard toolchain features may be used (e.g. Python's
random module, C's rand()/<random> in C++, System.Random in C#, java.util.Random,
Rust's rand crate from crates.io, Go's math/rand). No sorting-library shortcuts
(don't call a built-in sort() — implement the algorithm by hand). No exotic/third-party
frameworks.
Timing harness (same shape in every language)
nstarts at 1000.- Each loop iteration:
- Generate a fresh array of
nrandom integers (range roughly[0, 1_000_000)). Data generation is NOT timed. - Start a high-resolution monotonic timer.
- Run randomized quicksort on the array in place.
- Stop the timer; record
(n, elapsed_seconds).
- Generate a fresh array of
n *= 2for the next iteration.- Stop the loop when any of these is true:
- the elapsed time for the iteration just run exceeds 4.0 seconds,
- 25 iterations have run, or
nwould exceed 200,000,000 on the next iteration (memory safety cap), whichever comes first. (Each language will naturally reach a different maxnbefore hitting the 4s cutoff — that's expected and fine; faster/compiled languages should reach much largern.)
- Append every
(n, elapsed_seconds)pair, one per line, to a CSV fileresults/<lang>.csvwith headern,time_seconds. Also print the same rows to stdout as the run happens (assignment: "Print or log the results").
Per-language deliverable layout
Each language gets its own subfolder under HW3/<lang>/ containing:
- Source code (idiomatic, single top-level function decomposed into helpers as needed).
- A short
README.mdor build/run instructions (compiler/runtime + exact flags used). - Its run writes to
HW3/results/<lang>.csv.
Each agent also writes HW3/reports/<lang>_report.md with:
- Language + compiler/runtime version and any optimization flags used.
- Confirmation of how the random pivot is chosen (and RNG used).
- Any external code used, with citation (or "no external code used").
- The resulting
(n, time)table (or a summary if very long). - One paragraph: does the observed growth match expected O(n log n)? Any anomalies (JIT warmup, GC pauses, first-call overhead, etc.)?
Environment
Run inside WSL2 Ubuntu (distro name Ubuntu, 26.04 "Resolute Raccoon", default user
granite with passwordless sudo) for a consistent Linux environment across all languages.
Machine: AMD Ryzen 7 5800H (8 cores / 16 threads, ~3.2 GHz base), 32 GB RAM, Windows 11
Pro host, benchmarks executed inside WSL2 Ubuntu. Note the CPU in every report.
Toolchains already installed and confirmed working inside the distro:
gcc/g++15.2.0 (build-essential)python33.14.4java/javac(OpenJDK 25.0.4,default-jdk)go1.26.0dotnet10.0.400 (installed under/home/granite/.dotnet, symlinked into/usr/local/bin, so it resolves in any shell)rustc1.98.0 /cargo1.98.0 (via rustup, symlinked into/usr/local/bin)
Invocation convention — run every build/run command through WSL from the Windows side like this (works from both the Bash tool and the PowerShell tool):
wsl.exe -d Ubuntu -- bash -c "cd '/mnt/c/Users/granite/Documents/DSU/Algorithms 482/3/HW3/<lang>' && <build/run command>"
Note the space in Algorithms 482 — always single-quote the cd path inside the
outer double quotes exactly as shown. All Windows paths under this project are
reachable at the equivalent /mnt/c/... path inside WSL, and files written from
either side are immediately visible on the other (it's the same NTFS filesystem
mounted into the Linux VM), so plain Write/Edit/Read tools on the Windows
paths work fine for source files — only actually compiling/running needs to go
through wsl.exe.
Round 2 languages (added after the initial 7)
Per the student's request to expand coverage, 8 more languages were added: JavaScript (Node.js), TypeScript, F#, Zig, Common Lisp (SBCL), Free Pascal, x86-64 Assembly (NASM), and PHP. Several genuinely non-existent or effectively-dead languages the student also asked about (R++, PEARL, Opal, Mercury, Lucid, Euler, Cobra) were skipped as infeasible — no working modern toolchain exists for them. R, Prolog, Erlang, Elixir, Swift, and COBOL were also skipped for this round: none have apt packages in this environment (a limited archive mirror missing many otherwise-common packages), each would require a substantial from-source bootstrap, and this environment's WSL Linux-side state proved unreliable during setup (an idle-timeout was silently discarding installed packages, and at least one file was found corrupted after being written — both worked around, see below), making further from-source builds a poor time/risk tradeoff for a 15-point assignment already covering 15 languages.
Toolchains for the round-2 languages, all confirmed working, none available
via apt in this environment (installed via each project's official
binary/source release instead) — all resolve directly by name in any WSL
shell (symlinked into /usr/local/bin or wrapped there):
node/npm/npx— Node.js v22.18.0 (official linux-x64 tarball from nodejs.org)tsc— TypeScript 7.0.2 (installed vianpm install -g typescript); compile withtsc file.tsthen run the emitted.jswithnode- F# — no new install; use the existing dotnet 10.0.400 SDK with
-lang F#(e.g.dotnet new console -lang F# -o .) zig— Zig 0.13.0 (official linux-x86_64 tarball from ziglang.org)sbcl— SBCL 2.4.9 (official binary release from sbcl.org, wrapped at/usr/local/bin/sbcl, which setsSBCL_HOMEand execs the real runtime at/home/granite/toolchains/sbcl/src/runtime/sbcl— the binary distribution's ownrun-sbcl.shis broken in this install, do not use it)fpc— Free Pascal 3.2.2 (official linux-x86_64 tarball from SourceForge, wrapped at/usr/local/bin/fpc)nasm+ld— NASM 2.16.03 (built from source;ldis the system linker, already present) — for the Assembly entry, write x86-64 assembly and link against libc (viagccas the linker driver,extern-declaring libc functions likeprintf,srand,rand,clock_gettime,fopen/fprintf/fclose,malloc/free) rather than raw syscalls only — this is the standard, common way to write a nontrivial assembly program (raw-syscall-only I/O/float-formatting is needlessly obscure), and mirrors what "as common a library as possible" means for this languagephp— PHP 8.5.4 CLI (apt packagephp, one of the few round-2 languages actually available via apt here)
A note on this environment's reliability, relevant if anything needs
reinstalling: this WSL instance's Linux-side state (installed packages,
/etc/sudoers.d, even a script file's own contents) was observed to
reset/corrupt itself at least twice during setup, correlated with the VM's
default idle-auto-stop behavior — fixed by setting
vmIdleTimeout=-1 in %USERPROFILE%\.wslconfig and NOT relying on sudo
persisting (every root-requiring command in this project uses
wsl -d Ubuntu -u root -- ... directly instead of sudo). If a toolchain
that worked earlier suddenly isn't found, re-verify with a quick
--version-style check before assuming the implementation is at fault.
Final synthesis (done by the coordinating agent, not per-language agents)
- Combine all
results/<lang>.csvintoresults/all_results.csv. - Produce
results/combined_plot.png: line graph, x = n, y = time (seconds), one line per language, legend, title, axis labels — matplotlib (log-scale y-axis in a second plot if it helps readability, but include the plain linear-axis plot as the primary one since the assignment asks for "time along the y-axis"). reports/FINAL_COMPARISON.md: compliance check of every language report againstHW3.docx's requirements, cross-language comparison discussion, and note on CPU used.- No GitHub is used for any part of this (per instructions.txt) — everything stays local
under this
HW3/folder.