https://github.com/bouk/go-faster
You can always Go faster
https://github.com/bouk/go-faster
Last synced: about 1 year ago
JSON representation
You can always Go faster
- Host: GitHub
- URL: https://github.com/bouk/go-faster
- Owner: bouk
- Created: 2014-05-20T20:27:05.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-21T02:08:28.000Z (about 12 years ago)
- Last Synced: 2025-03-18T06:11:27.509Z (about 1 year ago)
- Language: Go
- Homepage: http://bouk.co
- Size: 167 KB
- Stars: 49
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-faster
## Installation
`go get github.com/bouk/go-faster`
## Basic usage
You can make any go program run faster by using more goroutines and channels! Example:
```bash
cat test.go
```
```go
package main
func a(c int) int {
c += 1
return c
}
func main() {
println(a(2))
}
```
```bash
go-faster test.go | tee test.go
```
```go
package main
func a(c int) chan int {
result := make(chan int)
go func() {
result <- func() int {
c += 1
return c
}()
}()
return result
}
func main() {
println(<-a(2))
}
```
```bash
go run test.go
3
```
Because the speed of a go program is measured in the amount of `go` statements and channels you can make any program faster by simply doing `go-faster `.
## Even faster
There is no limitation on the number of times you can run `go-faster` on your program.
```bash
go-faster test.go | tee test.go
```
```go
package main
func a(c int) chan chan chan int {
result := make(chan chan chan int)
go func() {
result <- func() chan chan int {
result := make(chan chan int)
go func() {
result <- func() chan int {
result := make(chan int)
go func() {
result <- func() int {
c += 1
return c
}()
}()
return result
}()
}()
return result
}()
}()
return result
}
func main() {
println(<-<-<-a(2))
}
```
We hope that one day we can have infinite goroutines and channels.