473,695 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SWIG overhead

Hi,
Im looking for some benchmarks comparing SWIG generated modules with
modules made directly with C/Python API. Just how much overhead does
SWIG give? Doing profile of my code I see, that it spends quiet some
time in functions like _swig_setattr_n ondinamic, _swig_setattr,
_swig_getattr.

Feb 1 '07 #1
10 3198
On 1 Feb 2007 02:21:35 -0800, Bart Ogryczak <B.********@gma il.comwrote:
Hi,
Im looking for some benchmarks comparing SWIG generated modules with
modules made directly with C/Python API. Just how much overhead does
SWIG give? Doing profile of my code I see, that it spends quiet some
time in functions like _swig_setattr_n ondinamic, _swig_setattr,
_swig_getattr.
Before you decide to go "low level" consider to use Boost.Python.
According to this( http://tinyurl.com/322d3p ) post it gives pretty
good performance.

P.S. The post does not contain numbers

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
Feb 1 '07 #2
On Thursday 01 February 2007 10:21 am, Bart Ogryczak wrote:
Hi,
Im looking for some benchmarks comparing SWIG generated modules with
modules made directly with C/Python API. Just how much overhead does
SWIG give? Doing profile of my code I see, that it spends quiet some
time in functions like _swig_setattr_n ondinamic, _swig_setattr,
_swig_getattr.
There was a EuroPython paper describing some benchmarks. It's from 2004 so
things have probably changed a bit (SIP is now fully documented for example).

http://people.web.psi.ch/geus/talks/...n2004_geus.pdf

Phil
Feb 1 '07 #3
On Feb 1, 12:12 pm, Phil Thompson <p...@riverbank computing.co.uk >
wrote:
On Thursday 01 February 2007 10:21 am, Bart Ogryczak wrote:
Hi,
Im looking for some benchmarks comparing SWIG generated modules with
modules made directly with C/Python API. Just how much overhead does
SWIG give? Doing profile of my code I see, that it spends quiet some
time in functions like _swig_setattr_n ondinamic, _swig_setattr,
_swig_getattr.

There was a EuroPython paper describing some benchmarks. It's from 2004 so
things have probably changed a bit (SIP is now fully documented for example).

http://people.web.psi.ch/geus/talks/...n2004_geus.pdf
Yeah, found that one googling around. But I havent fund anything more
up to date. I imagine, that the performance of all of these wrappers
has been improved since then. But the performance of Python/C API
would too?
Anyways, its not about exact number, its more about taking decision
if doing rewrite is worth its time.

Feb 1 '07 #4
Yeah, found that one googling around. But I haven´t fund anything more
up to date. I imagine, that the performance of all of these wrappers
has been improved since then. But the performance of Python/C API
would too?
Anyways, it´s not about exact number, it´s more about taking decision
if doing rewrite is worth it´s time.
The wrappers essentially create the boilerplate-code that invokes the Python
C-API. So whatever improvements the latter has been developed, the wrappers
will benefit from it. I doubt that there are major performance penalties
associated with any of them.

More important for a wrapper-decision is the question how easy they are to
use.
Diez

Feb 1 '07 #5
On Feb 1, 12:48 pm, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
Yeah, found that one googling around. But I havent fund anything more
up to date. I imagine, that the performance of all of these wrappers
has been improved since then. But the performance of Python/C API
would too?
Anyways, its not about exact number, its more about taking decision
if doing rewrite is worth its time.

The wrappers essentially create the boilerplate-code that invokes the Python
C-API. So whatever improvements the latter has been developed, the wrappers
will benefit from it.
Without doubt its true in case of SWIG, but if I understand
Python.Boost documentation correctly, it does *not* use Python/C API.
I doubt that there are major performance penalties associated with any ofthem.
Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/
europython2004_ geus.pdf
More important for a wrapper-decision is the question how easy they are to use.
Well, SWIG is easy to use. But Ive gotta make hundreds of millions of
calls, which do tasks as simple, as getting one int from an array and
returning it. With functions that simple SWIGs overhead seems to be a
problem.
Feb 1 '07 #6
Bart Ogryczak wrote:
On Feb 1, 12:48 pm, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
Yeah, found that one googling around. But I haven´t fund anything more
up to date. I imagine, that the performance of all of these wrappers
has been improved since then. But the performance of Python/C API
would too?
Anyways, it´s not about exact number, it´s more about taking decision
if doing rewrite is worth it´s time.

The wrappers essentially create the boilerplate-code that invokes the
Python C-API. So whatever improvements the latter has been developed, the
wrappers will benefit from it.

Without doubt it´s true in case of SWIG, but if I understand
Python.Boost documentation correctly, it does *not* use Python/C API.
It has to. In the end, marshalling data between e.g. python datastructures
and C++ is done that way.
>I doubt that there are major performance penalties associated with any of
them.

Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/
europython2004_ geus.pdf
Ok, I see. I really wonder what SWIG does.
Well, SWIG is easy to use. But I´ve gotta make hundreds of millions of
calls, which do tasks as simple, as getting one int from an array and
returning it. With functions that simple SWIG´s overhead seems to be a
problem.
Still I think you should first use wrappers for ease of use. Then when you
hit a performance bottleneck, it might be worth wrapping that class
manually. However, it _might_ of course be that this isn't integrating too
seamless with the wrapped classes, but I can't say anything about that
really.

Diez
Feb 1 '07 #7
On 2/1/07, Diez B. Roggisch <de***@nospam.w eb.dewrote:
Bart Ogryczak wrote:
On Feb 1, 12:48 pm, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
Yeah, found that one googling around. But I havent fund anything more
up to date. I imagine, that the performance of all of these wrappers
has been improved since then. But the performance of Python/C API
would too?
Anyways, its not about exact number, its more about taking decision
if doing rewrite is worth its time.

The wrappers essentially create the boilerplate-code that invokes the
Python C-API. So whatever improvements the latter has been developed, the
wrappers will benefit from it.
Without doubt its true in case of SWIG, but if I understand
Python.Boost documentation correctly, it does *not* use Python/C API.

It has to. In the end, marshalling data between e.g. python datastructures
and C++ is done that way.
As I understand it, part of the Boost.Python internals is a C++
wrapper over the Python C api, and there's no separate code generation
phase because it uses template magic to generate the wrappers. So
while obviously the C API is used at some level, it's not visible to
the wrapper author.
I doubt that there are major performance penalties associated with anyof
them.
Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/
europython2004_ geus.pdf

Ok, I see. I really wonder what SWIG does.
SWIG generates a low-level C module, and then a Python one on top of
it. It allows for quite some versatility in wrapping (because you can
have (almost) arbitrary Python code generated). Most of the other
tools generate a .pyd which you import directly.
Well, SWIG is easy to use. But Ive gotta make hundreds of millions of
calls, which do tasks as simple, as getting one int from an array and
returning it. With functions that simple SWIGs overhead seems to be a
problem.

Still I think you should first use wrappers for ease of use. Then when you
hit a performance bottleneck, it might be worth wrapping that class
manually. However, it _might_ of course be that this isn't integrating too
seamless with the wrapped classes, but I can't say anything about that
really.
Personally, I'd favor *correctness* first, then ease of use, and then speed..
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Feb 1 '07 #8
On Feb 1, 3:21 am, "Bart Ogryczak" <B.Ogryc...@gma il.comwrote:
Hi,
Im looking for some benchmarks comparing SWIG generated modules with
modules made directly with C/Python API. Just how much overhead does
SWIG give? Doing profile of my code I see, that it spends quiet some
time in functions like _swig_setattr_n ondinamic, _swig_setattr,
_swig_getattr.

This isn't exactly what you're looking for, but I tried SWIG a while
ago, back when I still had a C compiler, and then decided to use c-
types.

The reason: I've got an aversion to anything that generates huge
steaming piles of incomprehensibl e code. Especially when I found a
couple of bugs in a SWIG-generated module I'd gotten from someone
else. This wasn't SWIG's fault, it was the author's for not
understanding the API he was wrapping properly, but I had to dig into
the SWIG code before I could figure out what was going on.

Bottom line: the c-types module was a lot smaller, in Python, and
completely comprehensible. And while I didn't measure the performance,
I doubt if it was slower.

John Roth

Feb 1 '07 #9

JohnBottom line: the c-types module was a lot smaller, in Python, and
Johncompletely comprehensible. And while I didn't measure the
Johnperformance , I doubt if it was slower.

One advantage SWIG (or Boost.Python) has over ctypes is that it will work
with C++.

Skip

Feb 1 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3776
by: Ernie | last post by:
Hi, I am learning swig to use C codes from Python. Here is the swig file mvf.i: %module mvf %include "carrays.i" %array_class(double, doubleArray); %typemap(out) double, float "$result = PyFloat_FromDouble($1);" %include mvf.h
3
2812
by: Kevin Dahlhausen | last post by:
Could anyone post a simple setup.py script that uses a SWIG interface to C++ code and the mingw compiler? I followed some online samples, and am using the setup.cfg file to specify swig-c++=1. Trying to build using mingw out of the cygwin environment but the final call to link the extension calls directly to 'cc' which I think should really be g++ at that point.
1
2148
by: Java and Swing | last post by:
I am trying to wrap some C code I have. Currently I have something like... defs.h ----------- typedef unsigned long MY_DIGIT; myapp.c ------------- void MakeDigits(MY_DIGIT digits) {
2
4448
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
0
8649
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8586
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9004
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.