Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Repro #2, surface regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Feb 3, 2015
1 parent 5d6bcd1 commit 146c542
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions gcrepro/gcrepro.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"runtime"

Expand All @@ -24,14 +25,52 @@ func random(length int) []byte {

func main() {
data := random(256 * 1024 * 1024)

run(data, 1)
run(data, 1)
run(data, 1)
fmt.Println()
run(data, 8)
run(data, 8)
run(data, 8)

fmt.Println()
fmt.Println()

iter := 256 * 1024
burst(iter, 1)
burst(iter, 1)
burst(iter, 1)
fmt.Println()
burst(iter, 8)
burst(iter, 8)
burst(iter, 8)
}

func burst(iters int, threads int) {
runtime.GOMAXPROCS(threads)

ir, iw := io.Pipe()
or, ow := io.Pipe()

// Gather memory stats
start := new(runtime.MemStats)
runtime.ReadMemStats(start)

// Run the operation
go bufioprop.Copy(ow, ir, 1024)

input, output := []byte{0xff}, make([]byte, 1)
for i := 0; i < iters; i++ {
iw.Write(input)
or.Read(output)
}
ow.Close()

// Gather memory stats and report
end := new(runtime.MemStats)
runtime.ReadMemStats(end)

fmt.Printf("short bursts: gomaxprocs %d, allocs: %d, bytes: %d\n", runtime.GOMAXPROCS(0), end.Mallocs-start.Mallocs, end.TotalAlloc-start.TotalAlloc)
}

func run(data []byte, threads int) {
Expand All @@ -48,5 +87,5 @@ func run(data []byte, threads int) {
end := new(runtime.MemStats)
runtime.ReadMemStats(end)

fmt.Printf("Gomaxprocs %d, allocs: %d, bytes: %d\n", runtime.GOMAXPROCS(0), end.Mallocs-start.Mallocs, end.TotalAlloc-start.TotalAlloc)
fmt.Printf("long run: gomaxprocs %d, allocs: %d, bytes: %d\n", runtime.GOMAXPROCS(0), end.Mallocs-start.Mallocs, end.TotalAlloc-start.TotalAlloc)
}

0 comments on commit 146c542

Please sign in to comment.