Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed of swig wrappers

If I were to write several classes in c++ then use swig to do the conversion so I could later use them in python, would they run faster or slower than if I completely rewrote them in python? Or is there no noticable speed difference?

like image 202
a sandwhich Avatar asked Dec 18 '10 04:12

a sandwhich


1 Answers

The quality and speed of wrappers generated by SWIG is very good, and they will probably perform just as good as handcrafted wrappers.

From my experience, the wrappers themselves are very thin and add very little overhead to the native functions they wrap, making it a perfectly valid choice to use wrapped libraries in python or any other supported language, and is a good way to reuse code.

however, to be if you are interested in performance in addition to code reuse, wrapping native code will probably only pay off if you have some computationally intensive native functions, like multiplying matrices, computing MD5 or CRC, folding proteins etc.

on the other hand, sometimes you can just rewrite everything in an easy language like python or C# and enjoy better code and better tools, with comparable performance.

like image 62
Aviad Rozenhek Avatar answered Nov 13 '22 16:11

Aviad Rozenhek