I stumbled upon an interesting thing while checking the performance of memory allocation in GO.
package main import ( "fmt" "time" ) func main(){ const alloc int = 65536 now := time.Now() loop := 50000 for i := 0; i<loop;i++{ sl := make([]byte, alloc) i += len(sl) * 0 } elpased := time.Since(now) fmt.Printf("took %s to allocate %d bytes %d times", elpased, alloc, loop) }
I run this on a Core-i7 2600 with a 64-bit version of go 1.6 (also similar results on 32 bits) and 16 GB of RAM (on WINDOWS 10) so when alloc is 65536 (exactly 64 KB), it works for 30 seconds (!!!!). When alloc 65535, ~ 200 ms is required. Can someone please explain this to me? I tried the same house code with my core i7-920 @ 3.8GHZ, but it did not show the same results (both took about 200 ms). Does anyone know what is going on?
source share