Skip to content

seven7777777/rust-ffi-c-vs-go-cgo-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-ffi-c-vs-go-cgo-c

一个简单的rust ffi和go cgo性能对比
版本:
rustc 1.43.0 (4fb7144ed 2020-04-20)
go version go1.13.9 linux/amd64
测试方法:
1.调用一个c动态库中的echo函数:char* echo(const char* name, size_t keylen, size_t* vallen)
2.每个实现调用接口1百万次,通过time计时,测试结果:
c调用c动态链接库
=====run cmain call clib=====
real 0m0.052s
user 0m0.026s
sys 0m0.026s
rust ffi调用c动态链接库
=====run rmain call clib=====
real 0m0.050s
user 0m0.027s
sys 0m0.023s
go cgo调用c动态链接库
=====run gmain call clib=====
real 0m0.146s
user 0m0.118s
sys 0m0.029s
结论:单从接口ffi/cgo的单向(foreign->c)调用的性能来看:1.ffi是cgo的三倍左右 2.ffi方式的性能接近c的原生调用性能。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published