Page 1 of 1

General Python question

Posted: Fri Jul 20, 2012 10:07 pm
by BackRaw
Hi,

is it faster to have a C++ code where you write boost.python mostly than to have Python code with the same?

Like

Syntax: Select all

import os

if __name__ == "__main__":
x = [3, 6, 7, 9]
z = os.getcwd()

# do something else like reading a file and display its contents to the screen
and

Syntax: Select all

#include <stdlib.h> // for getcwd()
#include <boost/python.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(test) // or whatever you write the main thing in...
{
char path[1024];

list<int> x({4, 6, 7, 8}); // or however you initialize a list object directly, you know what I mean
getcwd(path, 1024);
str z(path);

// do something else like reading a file and display its contents to the screen
}

I wanna know if it makes a speed difference to have actually the same code in a C++ library.

Posted: Fri Jul 20, 2012 10:21 pm
by your-name-here
I am not sure. My guess is C++ will always be faster. Boost runs your code natively unlike a script which is run through the interpreter.

Posted: Fri Jul 20, 2012 10:42 pm
by BackRaw
your-name-here wrote:I am not sure. My guess is C++ will always be faster. Boost runs your code natively unlike a script which is run through the interpreter.


That's an argument! Thanks :)