https://github.com/deanpdx/struct-benchmarks
https://github.com/deanpdx/struct-benchmarks
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/deanpdx/struct-benchmarks
- Owner: DeanPDX
- License: mit
- Created: 2024-03-26T15:33:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T15:50:53.000Z (about 2 years ago)
- Last Synced: 2025-02-21T10:16:24.841Z (over 1 year ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Struct Benchmarks
This is a contrived benchmark to illustrate differences between iterating over an array of type `[]T` and `[]*T` and how much it matters if we `range` over them versus index into them. See [this thread](https://forum.golangbridge.org/t/can-someone-kindly-eli5-the-difference-between-using-slice-of-pointers-and-slice-of-structs/34905) for more details.
## Running the benchmarks
After cloning the repository, `go test -bench .` should yield something like this:
```bash
goos: windows
goarch: amd64
pkg: github.com/DeanPDX/struct-benchmarks
cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
BenchmarkRangePointers-8 654621 1839 ns/op
BenchmarkRangeStructs-8 499588 2332 ns/op
BenchmarkIndexPointers-8 704833 1732 ns/op
BenchmarkIndexStructs-8 666658 1844 ns/op
PASS
ok github.com/DeanPDX/struct-benchmarks 5.002s
```