diff --git a/ch03/execTime.go b/ch03/execTime.go index 7e8bd57..b26f031 100644 --- a/ch03/execTime.go +++ b/ch03/execTime.go @@ -2,9 +2,26 @@ package main import ( "fmt" + "runtime" "time" ) +type data struct { + i, j int +} + func main() { + var N = 40000000 + var structure []data + for i := 0; i < N; i++ { + value := int(i) + structure = append(structure, data{value, value}) + } + + start := time.Now() + runtime.GC() + duration := time.Since(start) + fmt.Println("It took GC()", duration, "to finish") + _ = structure[0] }