Discover Packages
github.com/joshuaandrew/learning
std
test
labs21
package
Version:
v0.0.0-...-6c2044b
Opens a new window with list of versions in this module.
Published: Feb 6, 2022
License: Apache-2.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Go的runtime包中使用goc机制实现Go的底层结构,所以判断goc机制应该不需要像cgo调用那样做防阻塞的保护,调用效率应该会高很多,这里做了一个测试goc机制调用c的实验。
实验结果:
$ go test -gcflags '-N' --bench="."
testing: warning: no tests to run
PASS
Benchmark_Go_Call_C 500000000 3.84 ns/op
Benchmark_GO_Call_GO 500000000 3.78 ns/op
ok labs21 4.593s
对比于labs20中的测试结果,效率的确高了很多,但是goc机制不允许包含标准c的头文件,是一个比较麻烦的事情,但是假设要用go实现一个脚本语言或调用脚本语言,用goc机制会获得更高的执行效率,当然实现起来代价也高了很多就是了。
如果可以找到一个快速把C的调用转换成类似runtime库中的.s文件那样的汇编代码,就可以做到无代价的包装C的库。
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.