Skip to content

runtime: go1.5 works slower than go1.4? #11114

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

Closed
awesomeleo opened this issue Jun 8, 2015 · 4 comments
Closed

runtime: go1.5 works slower than go1.4? #11114

awesomeleo opened this issue Jun 8, 2015 · 4 comments

Comments

@awesomeleo
Copy link

I have built and installed go1.5 from source, and use it to build my project. But i find it works slower than
built from go1.4.2. the performance is only 60% as it built from go1.4.2. My project uses a lot of goroutines to call rocksdb which is implmented by c.
I have heared of go1.5 will work faster than go1.4, but what i see is not as that at current time. Will go1.5 work faster in release version?

@bradfitz
Copy link
Contributor

bradfitz commented Jun 8, 2015

Some parts are faster and some parts are slower. On average, it's faster overall.

Do you have a specific repro case?

@awesomeleo
Copy link
Author

Dear bradfitz,
Thanks for your reply. I have made a test program, test1 works faster in go1.5, but test2 works slower in go1.5. I think maybe goroutine works slow in go1.5.

package main

// #include <stdio.h>
// #include <stdlib.h>
/*
void process(char *str) {
    //printf("%s\n", str);
    if(str!=NULL)
    {
        strstr(str,"Hello");
        strstr(str,"Cgo");
    }
}
*/
import "C"
import "unsafe"
import (
    "fmt"
    "time"
)

func test1() {
    s := "Hello Cgo"
    cs := C.CString(s)
    C.process(cs)
    C.free(unsafe.Pointer(cs))
}

func test2(done chan int) {
    s := "Hello Cgo"
    cs := C.CString(s)
    C.process(cs)
    C.free(unsafe.Pointer(cs))
    done <- 1
}
func main() {

    //test1
    count := 1000000
    t1 := time.Now()    
    for i := 0; i < count; i++ {
        test1()
    }
    t2 := time.Since(t1)
    fmt.Println("test1 time used:", t2)




    //test2
    count = 1000000
    t1 = time.Now()
    done := make(chan int)
    for i := 0; i < count; i++ {
        go test2(done)
    }

    for {
        <-done
        count = count - 1
        if count == 0 {
            break
        }
    }
    t2 = time.Since(t1)
    fmt.Println("time used:", t2)
}

@bradfitz
Copy link
Contributor

bradfitz commented Jun 8, 2015

Try with GOMAXPROCS=1. The default in Go 1.5 will be that GOMAXPROCS=NumCPU

@bradfitz
Copy link
Contributor

bradfitz commented Jun 8, 2015

I suspect this might just be a dup of #9704

Let's move this to the golang-nuts@ mailing list until a specific bug is identified.

@bradfitz bradfitz closed this as completed Jun 8, 2015
@mikioh mikioh changed the title go1.5 works slower than go1.4? runtime: go1.5 works slower than go1.4? Jun 9, 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

3 participants