Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/comiple, runtime: channels: performance gap #11316

Closed
ghost opened this issue Jun 21, 2015 · 1 comment
Closed

cmd/comiple, runtime: channels: performance gap #11316

ghost opened this issue Jun 21, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 21, 2015

Run test with N = 1,2,3,4...

package main

import (
    "fmt"
    "sync"
    "time"
)

var N = 1

type T interface{}

func main() {
    var wg sync.WaitGroup
    ch := make(chan T)
    wg.Add(1)
    go func() {
        defer wg.Done()
        test(ch)
    }() 
    for i := 0; i < N; i++ {
        ch <- 1
    }   
    close(ch)
    wg.Add(1)
    go func() {
        defer wg.Done()
        test(ch)
    }() 
    wg.Wait()
}

func test(ch chan T) T { 
    t := time.Now()
    var v T 
    var ok bool
    for i := 0; i < N; i++ {
        v, ok = <-ch
    }   
    fmt.Printf("%v, closed: %v\n", time.Since(t), !ok)
    return v
}

N = 1:

705ns, closed: false
360ns, closed: true

N = 2:

_6.393µs_, closed: false
324ns, closed: true

N = 3: (less than N = 2. Why?)

_2.397µs_, closed: false
384ns, closed: true

N = 4:

_7.476µs_, closed: false
423ns, closed: true

N = 5: (less than N = 4 and N = 2. Why?)

_3.132µs_, closed: false
510ns, closed: true

System spec:

Linux 4.0.4-303.fc22.x86_64
go1.4.2 linux/amd64

@bradfitz
Copy link
Contributor

I don't think this is statistically significant. You only have a couple samples.

Also, no performance work is being done on the released Go 1.4 branch anymore. Please post any interesting benchmarks about Go 1.5 to the golang-nuts@ mailing list.

@mikioh mikioh changed the title channels: performance gap cmd/comiple, runtime: channels: performance gap Jun 23, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants