4 ms·
> Of course, there is massive overhead in doing so. Some concrete numbers for Go: • Calling C from Go: ~40-50ns [1] [2] • Calling Go from C: ~100-200ns [3]
by Mawr 3y ago
> Of course, there is massive overhead in doing so.
Some concrete numbers for Go:
• Calling C from Go: ~40-50ns [1] [2]
• Calling Go from C: ~100-200ns [3]
[1] "Cgo calls take about 40ns, about the same time encoding/json takes to parse a single digit integer. On my 20 core machine Cgo call performance scales with core count up to about 16 cores, after which some known contention issues slow things down." (https://shane.ai/posts/cgo-performance-in-go1.21 https://shane.ai/posts/cgo-performance-in-go1.21)
[2] "In response to the "cgo is slow" questions, this shows that cgo calls are about 50ns on my four-year-old x86 MacBook Pro. Is that fast or slow? It depends on what the cgo call is doing. If it's executing a single add instruction, an extra 50ns is slow. If it's doing something more substantial, an extra 50ns may be nothing at all." – rsc (https://news.ycombinator.com/item?id=36006347 https://news.ycombinator.com/item?id=36006347)
[3] "Calls from C to Go on threads created in C require some setup to prepare for Go execution. On Unix platforms, this setup is now preserved across multiple calls from the same thread. This significantly reduces the overhead of subsequent C to Go calls from ~1-3 microseconds per call to ~100-200 nanoseconds per call." (https://go.dev/doc/go1.21 https://go.dev/doc/go1.21)