GO性能提升的相关改动

随着GO版本的迭代,GO语言的性能也在不断提升。下文梳理下GO种提升性能的几处改动。 math/rand/v2 Go 1.22 版本引入,提供了一个新的随机数生成器,性能更好。 代码测试如下: package main import ( "math/rand" randV2 "math/rand/v2" "testing" ) func BenchmarkRand(b *testing.B) { b.StartTimer() for range b.N { rand.Intn(100) } } func BenchmarkRandV2(b *testing.B) { b.StartTimer() for range b.N { randV2.IntN(100) } } 测试结果 goos: darwin goarch: amd64 pkg: test cpu: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz BenchmarkRand-12 84788529 14.24 ns/op BenchmarkRandV2-12 154128462 7.790 ns/op math/rand/v2 不需要设置随机种子,使用加密安全的随机数生成器。 Go maps with Swiss Tables Go 1.24版本引入,使用 Swiss Table 的理念,全新重写了map。直接使用Go1....

November 2, 2025 · 1 min · 149 words