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

runtime/cgo: cgo call on Windows slower than Linux #5116

Closed
gopherbot opened this issue Mar 23, 2013 · 6 comments
Closed

runtime/cgo: cgo call on Windows slower than Linux #5116

gopherbot opened this issue Mar 23, 2013 · 6 comments

Comments

@gopherbot
Copy link

by Vova616:

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
go test bitbucket.org/StephaneBunel/xxhash-go -bench=".*" 
on linux and windows

What is the expected output?
almost no performance difference in Benchmark_xxhash32 function

What do you see instead?
windows is 2 times slower than cgo in Benchmark_xxhash32 function

Which operating system are you using?
windows 7 64bit

Which version are you using?  (run 'go version')
go version devel +7778f3df0d19 Sun Mar 10 12:50:44 2013 -0400 windows/amd64 

Please provide any additional information below.
It happends on 32bit as well
Benchmark_xxhash32 function is the only one that using cgo.

i7-3770K @ 3.50GHz windows 7 64bit 
 
go version devel +7778f3df0d19 Sun Mar 10 12:50:44 2013 -0400 linux/amd64 
go test bitbucket.org/StephaneBunel/xxhash-go -bench=".*" 
 
 Benchmark_xxhash32      50000000                57.4 ns/op 
 Benchmark_CRC32IEEE     10000000               162 ns/op 
 Benchmark_Adler32       50000000                48.7 ns/op 
 Benchmark_Fnv32 20000000               128 ns/op 
 Benchmark_MurmurHash3Hash32      1000000              1953 ns/op 
 
go version devel +7778f3df0d19 Sun Mar 10 12:50:44 2013 -0400 windows/amd64 
go test bitbucket.org/StephaneBunel/xxhash-go -bench=".*" 
 
 Benchmark_xxhash32      20000000               110 ns/op 
 Benchmark_CRC32IEEE     10000000               161 ns/op 
 Benchmark_Adler32       50000000                54.1 ns/op 
 Benchmark_Fnv32 20000000               130 ns/op 
 Benchmark_MurmurHash3Hash32      1000000              1954 ns/op 

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g/8g
@alexbrainman
Copy link
Member

Comment 1:

It looks like your C code is very quick.
From:
# hg st
# go test -run=NONE -bench=xxh
PASS
Benchmark_xxhash32      10000000               137 ns/op
Benchmark_goxxhash32    20000000                99.5 ns/op
ok      bitbucket.org/StephaneBunel/xxhash-go   3.618s
if I just put "return" at the start of you C function, like:
# hg st
M C/xxhash.c
# hg diff
diff -r c77f1e3b34a6 C/xxhash.c
--- a/C/xxhash.c        Sun Mar 10 18:58:14 2013 +0100
+++ b/C/xxhash.c        Mon Mar 25 13:57:49 2013 +1100
@@ -135,6 +135,7 @@
 unsigned int XXH32(const void* input, int len, unsigned int seed)
 {
+       return 0;
 #if 0
        // Simple version, good for code maintenance, but unfortunately slow for small inputs
        void* state = XXH32_init(seed);
# go test -run=NONE -bench=xxh
PASS
Benchmark_xxhash32      20000000               107 ns/op
Benchmark_goxxhash32    20000000                99.2 ns/op
ok      bitbucket.org/StephaneBunel/xxhash-go   4.349s
#
benchmark does not change much. So really you are not benchmarking your code, but how
fast Go to C interface is. You have discovered that linux is running switching code
faster then windows, and, perhaps, it is. Feel free to improve that, if you like.
Alex

@gopherbot
Copy link
Author

Comment 2 by Vova616:

Yeah you are right, I'm searching right now why this is happening exactly
1.0.3 switch is faster than tip switch btw
go version go1.0.3 (386)
Benchmark_xxhash32      50000000                45.4 ns/op
Benchmark_goxxhash32     5000000               364 ns/op
go version devel +f78c5036b7f6 Mon Mar 25 08:58:13 2013 -0700 windows/386
Benchmark_xxhash32      50000000                69.6 ns/op
Benchmark_goxxhash32    50000000                61.0 ns/op

@davecheney
Copy link
Contributor

Comment 3:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 4:

Labels changed: added performance.

@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 5:

It's pretty hard to get excited about 50 nanoseconds.

Labels changed: added priority-someday, removed priority-later.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 6:

Status changed to Unfortunate.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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

5 participants