From 183f57f239fe0073fbe776863ca544fec23fd246 Mon Sep 17 00:00:00 2001 From: Mihalis Tsoukalos Date: Tue, 22 Jan 2019 13:46:35 +0200 Subject: [PATCH] Find duration of command --- ch03/execTime.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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] }