bnagy / gapstone

gapstone is a Go binding for the capstone disassembly library
Other
151 stars 43 forks source link

Add DisasmIter for improved performance #21

Closed bentay closed 6 years ago

bentay commented 7 years ago

This adds a DisasmIter() to the engine that returns a channel of instructions and leverages cs_disasm_iter. According to capstone.h "some benchmarks shown that cs_disasm_iter() can be 30% faster on random input." Benchmark data with new changes below:

BenchmarkBasicX86Small-8          200000              8839 ns/op
BenchmarkBasicX86Medium-8           2000            739959 ns/op
BenchmarkBasicX86Large-8               5         277681297 ns/op
BenchmarkBasicX86XLarge-8              1        33275348009 ns/op
BenchmarkIterX86Small-8           100000             18217 ns/op
BenchmarkIterX86Medium-8            1000           1371163 ns/op
BenchmarkIterX86Large-8               10         139074940 ns/op
BenchmarkIterX86XLarge-8               1        13919601258 ns/op
PASS
ok      _/Users/bentay/capstone/gapstone      58.789s
bentay commented 7 years ago

Ah, C.CBytes is apparently a newish feature. https://golang.org/doc/go1.7#cmd_cgo

ayoubfaouzi commented 6 years ago

Hello @bnagy do you think we can merge this ? :+1:

lunixbochs commented 6 years ago

Maybe compare to https://github.com/lunixbochs/capstr performance? I heavily optimized the C->Go interface and allocations, as cgo is a bit slow.