Notes / Lang Lab
Fortran, VB.NET, OCaml and COBOL against C, after OpenAI's announcement
Fortran ties C, VB.NET pays for its overflow checks, OCaml allocates better than anyone, and COBOL costs 5× or 700× C on the same compiler depending only on how its arithmetic is written.
On 19 October OpenAI announced (opens in new tab) that its models had become much better at low-resource programming languages, the ones with little public code to learn from: COBOL, Fortran, Visual Basic and OCaml. A model writing better code in a language says nothing about how that language performs, and that is exactly what Lang Lab measures, so I added all four.
How it is measured
Lang Lab runs the same 18 algorithms in every language, from hash maps and sorting to matrix multiplication and tree inference, and every implementation has to print the same checksum before its number counts. Instead of timing them, which on shared CI runners is mostly noise, it counts the CPU instructions each program executes under QEMU at two input sizes and subtracts one from the other, so process startup and JIT warmup cancel out. Results are relative to C: 1.00× is C, and lower is better. Instructions are not seconds, but on compute-bound code they predict the wall-clock order well (R² 0.91, see the metric validity study (opens in new tab)), and anyone can reproduce them on any machine.
Fortran: level with C
Fortran came second out of 17 languages at 1.05× C, ahead of Rust at 1.11×. It matches or beats C on 8 of the 18 benchmarks and stays within 3% on another 5. That makes sense: gfortran shares gcc's backend, and it is built from the same image with the same -O2 flags as the C baseline. Its worst axis is the hash map at 1.31×, where Fortran has no built-in map and the table is written by hand, exactly as in C.
I expected it to be fast on the numeric benchmarks and slower on the rest. It is close to C everywhere.
VB.NET: C# with overflow checks
VB.NET runs on the same .NET 9 runtime as C#, with the same JIT and the same garbage collector, and still does about 1.4× the work of C# (2.11× C against 1.49×). Almost all of that gap is one default: Visual Basic checks every integer operation for overflow and C# does not. I measured it with the checks on, because that is what anyone writing VB gets without touching a setting.
The numbers show it. On allocation, with little integer arithmetic, they tie (0.46× C against 0.45×). On k-means, which is all integer math, VB.NET is at 3.01× and C# at 1.41×; on sha256, 2.54× against 1.59×.
OCaml: the best cell in the matrix
OCaml lands at 2.68× C overall, next to Kotlin and Java, but on binary-trees, which allocates and frees millions of small objects, it does 0.19× the work of C: the best result of the 17 languages on any benchmark. Its generational collector allocates by bumping a pointer, while C pays a malloc and a free for every node.
Its weak spot is the hash map with string keys, at 18.3×, and its integers are 63-bit, so the benchmarks that expect 32- or 64-bit arithmetic need explicit masking.
COBOL: the compiler decides
COBOL used to be in Lang Lab, and I removed it in July: most of its cost came from emulating what the language lacks, such as bit operations and big numbers, so it measured the emulation rather than COBOL. This time it is a side study (opens in new tab) outside the ranking, on the 15 benchmarks COBOL can run without hand-rolled machinery, with two compilers: GnuCOBOL 3.2 and gcobol, the COBOL front end that now ships with GCC.
Written the natural way, with COMPUTE and expressions, COBOL costs from 26× to almost 7,000× C on GnuCOBOL. GnuCOBOL sends every multiplication and division through a decimal arithmetic library, even when the operands are plain binary integers. A fast path exists in its source, behind an #if 0 with a "TODO: merge of fast math" comment, and it is still there in the 19 October nightly build.
gcobol has no decimal library, so I expected it to fix that. With the same natural code it is worse: slower than GnuCOBOL on 12 of the 14 benchmarks where both give the right answer. It only gets fast when the arithmetic is written in a restricted style: one verb per statement (ADD, MULTIPLY, DIVIDE ... REMAINDER), binary variables everywhere, no expressions, even the constants turned into named variables. Then 11 of the 15 benchmarks land between 4.9× and 7.3× C, on the same compiler that does 700× with the natural version.
Calls and floating point stay expensive either way. The benchmarks dominated by calls, recursion and dynamic dispatch remain at 18× to 64× C, and mandelbrot at 529×, because every call and every floating-point operation goes through the runtime library.
Along the way I hit two bugs in gcobol 15.2: a tight integer loop that never terminates at -O2 unless you add -fno-strict-aliasing, and a floating-point SUBTRACT ... GIVING that stores 0, which is why the natural mandelbrot printed the wrong checksum. Both are in the repository as minimal reproducers.
What I take from it
What interests me about OpenAI's news is how much code written in these languages is still in use, and the numbers say that code is not slow because it is old. Fortran performs like C, VB.NET like C# plus the price of its safety checks, OCaml allocates better than anything else I measured, and COBOL can get within a few times C, but only with the right compiler and arithmetic written in a very particular way.
I wonder how much of the COBOL running in banks and government agencies today is paying for the toolchain it was built with, and whether a model that writes better COBOL could help rewrite that arithmetic too.
Every number here is reproducible: the code, the version-pinned Dockerfiles and the raw results are in the Lang Lab repository (opens in new tab).