C | 5.2s | gcc test.c
|
C++ | 1m 25s | g++ test.cpp
|
Zig | 10.1s | zig build-exe test.zig
|
Nim | 45s | nim c test.nim
|
Rust | Stopped after 30 minutes | rustc test.rs
|
Swift | Stopped after 30 minutes | swiftc test.swift
|
D | Segfault after 6 minutes | dmd test.d
|
V | 0.6s | v test.v
|
I wrote a small program that generates 400 000 lines of code in several languages to benchmark their compilation speed.
All compilers (except Go) don't do optimization in this benchmark.
update Turns out generating one function with 400k lines of code is a bad idea :) Go and D segfault, Java simply refuses to compile. I'll modify the test soon.
You can read the code of the generator here.
It's a bit silly, all it does is generate the following pair of statements 200 000 times:
a = 1 println(a) a = 2 println(a) ...
I'm aware that in no way does this represent real code, but it can give a general picture, and all compilers face the same challenge.
Rust and Swift took too long to compile 400k lines, so I tried smaller numbers:
# lines | Rust | Swift | D |
2k | 3.4s | 0.8s | |
4k | 9.0s | 1.0s | |
8k | 30.8s | 2.3s | |
20k | 3m 52s | 11.8s | 4.7s |
100k | - | 5m 57s | segfault |