Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bygui86/go-pointers
Go sample project to understand difference between pointer and copy
https://github.com/bygui86/go-pointers
Last synced: 2 days ago
JSON representation
Go sample project to understand difference between pointer and copy
- Host: GitHub
- URL: https://github.com/bygui86/go-pointers
- Owner: bygui86
- License: apache-2.0
- Created: 2019-08-21T14:41:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-15T15:42:27.000Z (almost 5 years ago)
- Last Synced: 2023-03-07T10:58:03.795Z (almost 2 years ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go pointer vs copy
Go sample project to understand difference between pointer and copy## Instructions
### Normal
```
# by copy
go test ./... -bench=BenchmarkMemoryStackSingle -benchmem -run='^$' -count=10 > stack.txt && benchstat stack.txt
# by pointer
go test ./... -bench=BenchmarkMemoryHeapSingle -benchmem -run='^$' -count=10 > head.txt && benchstat head.txt
```### Normal - Limiting the processor
```
# by copy
GOMAXPROCS=1 go test ./... -bench=BenchmarkMemoryStackSingle -benchmem -run='^$' -count=10 > stack.txt && benchstat stack.txt
# by pointer
GOMAXPROCS=1 go test ./... -bench=BenchmarkMemoryHeapSingle -benchmem -run='^$' -count=10 > head.txt && benchstat head.txt
```### Mutiple
```
# by copy
go test ./... -bench=BenchmarkMemoryStackMultiple -benchmem -run='^$' -count=10 > stack.txt && benchstat stack.txt
# by pointer
go test ./... -bench=BenchmarkMemoryHeapMultiple -benchmem -run='^$' -count=10 > head.txt && benchstat head.txt
```### Mutiple - Limiting the processor
```
# by copy
GOMAXPROCS=1 go test ./... -bench=BenchmarkMemoryStackMultiple -benchmem -run='^$' -count=10 > stack.txt && benchstat stack.txt
# by pointer
GOMAXPROCS=1 go test ./... -bench=BenchmarkMemoryHeapMultiple -benchmem -run='^$' -count=10 > head.txt && benchstat head.txt
```---
## Links
* https://medium.com/@blanchon.vincent/go-should-i-use-a-pointer-instead-of-a-copy-of-my-struct-44b43b104963