Mahdi
All posts
vgobenchmarks

V versus Go, measured on the same machine

Compile times, binary size and runtime for V 0.5.2 and Go 1.27.1 on identical work, plus the language differences that show up in the first hour of porting.

V is usually described as faster to compile than Go. I wanted to check that rather than repeat it, so I ran the same program through both: sum a slice of 200,000 ints, 100 times.
package main

func sumAll(numbers []int) int {
    total := 0
    for _, n := range numbers {
        total += n
    }
    return total
}

func main() {
    numbers := make([]int, 200_000)
    for i := range numbers {
        numbers[i] = i
    }
    acc := 0
    for i := 0; i < 100; i++ {
        acc += sumAll(numbers)
    }
    println("go:", acc)
}
V 0.5.2 (bb0d229) and Go 1.27.1, Windows, same machine, best of five after a warm-up run. Both binaries built with release flags — v -prod, since a default V build is roughly 30x slower here and 1.5x larger:V 0.5.2Go 1.27.1Compile, cache empty0.68s3.55sCompile, warm cache5.93s0.10sRun, best of 514.6ms15.4msBinary339 kB1812 kBRuntime is a tieThat is the result I did not expect. I had recorded V at 36ms against Go's 16ms and written it up as "a wash, roughly 2x on integer arithmetic, not worth an argument."The 36ms was my error. It came from a default V build, not a release build:BuildBinaryBest of 5v (default)519 kB438msv -cc gcc498 kB150msv -prod339 kB14.6msgo build1812 kB15.4msWith -prod, V is not 2x slower — it is marginally faster than Go on the same integer loop, and inside the noise of a scheduler.The lesson is about the method rather than the language. I had three numbers in a table and no flag recorded next to them, so a build-mode difference read as a property of the language. A benchmark without its build flags is three numbers and no fact.Go is much faster to recompileV's headline is fast compilation, and cold builds bear that out: 0.68s against 3.55s.Warm is the opposite. A V recompile is 5.93s — barely faster than cold — against Go's 0.10s once GOCACHE is populated. That is a 59x gap, and it lands on the loop that matters day to day.The reason is the pipeline. V compiles to C and hands it to a C compiler, so every change re-enters the C toolchain and that work is not cached the way GOCACHE caches Go's own packages.If you are tightening a loop with a save-rebuild-run cycle, Go wins it by a wide margin. Cold-start once and you pay 0.68s instead of 3.55s.V's binary is about a fifth of Go's339 kB against 1812 kB. Go's binaries are famously large because they carry the runtime and type metadata for garbage collection. V compiles to C, so the output is closer to what a C compiler produces.What else movedGoVMutabilityEverything mutablemut required, compiler enforcedFormattergofmt -l is idempotentv fmt -verify also convergesString helpersstrings.Split(s, ",")"s".split(",")Exitos.Exit(0)exit(0), builtinModule filego.modv.modBoth formatters converge — I had the V row claiming otherwise and the check that caught it is in scripts/verify-v-claims.mjs.The mutability default is the part I like most about V, and it is the part that costs a Go programmer nothing. Everything in Go is mutable unless you go looking for a type that is not, which means every line you read has to be checked for aliasing. In V, mut is written at the point where mutation is intended, so reading the declaration tells you whether a variable changes.Where I would stopIf I already knew Go, I would stay on Go for anything with a dependency ecosystem I care about. V's advantage is compile speed on a cold cache, smaller binaries, and enforced mutability. None of those are reasons to rewrite working code.V is worth learning for the language design, and worth using where the compile and binary-size numbers matter — a CLI that ships as one file, or a build that starts from scratch on every CI run.

Related