This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
ctx, task := trace.NewTask(context.Background(), "main start") | |
var wg sync.WaitGroup | |
wg.Add(2) | |
go func() { | |
defer wg.Done() | |
r := trace.StartRegion(ctx, "reading file") | |
defer r.End() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type struct1 struct { | |
a, b int64 | |
c, d float64 | |
e *struct2 | |
} | |
type struct2 struct { | |
f, g int64 | |
h, i float64 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkAllocationEveryMs(b *testing.B) { | |
// need permanent allocation to clear see when the heap double its size | |
var s *[]int | |
tmp := make([]int, 1100000, 1100000) | |
s = &tmp | |
var a *[]int | |
for i := 0; i < b.N; i++ { | |
tmp := make([]int, 10000, 10000) | |
a = &tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type File struct { d int } | |
func main() { | |
p := openFile("t.txt") | |
content := readFile(p.d) | |
println("Here is the content: "+content) | |
} | |
func openFile(path string) *File { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"go/scanner" | |
"go/token" | |
"io/ioutil" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "math/rand" | |
func main() { | |
println(run()) | |
} | |
//go:noinline | |
func run() int { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
a := 1 | |
b := 2 | |
if true { | |
add(a, b) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
done := make(chan bool, 1) | |
var mu sync.Mutex | |
// goroutine 1 | |
go func() { | |
for { | |
select { | |
case <-done: | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Item = int | |
type waiter struct { | |
n int | |
c chan []Item | |
} | |
type state struct { | |
items []Item | |
wait []waiter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func emptyInterface(i interface {}) { | |
s := i.(*MultipleFieldStructure) | |
y = s | |
} |
NewerOlder