add: slice adv. ops. exercises

This commit is contained in:
Inanc Gumus
2019-03-05 23:32:32 +03:00
parent e379976af4
commit 9c96082326
19 changed files with 810 additions and 99 deletions

View File

@ -0,0 +1,24 @@
package api
import (
"fmt"
"math/rand"
"runtime"
)
// DO NOT TOUCH THE FOLLOWING CODE
// THIS IS THE API
// YOU CANNOT CONTROL IT! :)
// Read returns a huge slice (allocates ~65 MB of memory)
func Read() []int {
return rand.Perm(2 << 22)
}
// Report cleans the memory and prints the current memory usage
func Report() {
var m runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&m)
fmt.Printf(" > Memory Usage: %v KB\n", m.Alloc/1024)
}