Skip to content

Instantly share code, notes, and snippets.

@gokhanm
Created December 26, 2023 08:48
Show Gist options
  • Save gokhanm/ac62b9c716b69184d0ec5c69f7603c1e to your computer and use it in GitHub Desktop.
Save gokhanm/ac62b9c716b69184d0ec5c69f7603c1e to your computer and use it in GitHub Desktop.

Revisions

  1. gokhanm renamed this gist Dec 26, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. gokhanm created this gist Dec 26, 2023.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    // https://github.com/egonelbre/exp/blob/main/bench/goroutine/main.go
    package main

    import (
    "fmt"
    "runtime"
    "sync"

    "github.com/loov/hrtime"
    )

    func main() {
    const P = 128
    const K = 100
    const N = 10000

    {
    bench := hrtime.NewBenchmarkTSC(K)
    for bench.Next() {
    var wg sync.WaitGroup
    wg.Add(P)
    for k := 0; k < P; k++ {
    go func() {
    for i := 0; i < N; i++ {
    runtime.Gosched()
    }
    wg.Done()
    }()
    }
    wg.Wait()
    }
    hist := bench.Histogram(10)
    hist.Divide(N * P / runtime.NumCPU())
    fmt.Println("gosched\n", hist.StringStats())
    }

    }