Does embedding c++ code in python make your python application faster? [closed] - c++

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Does embedding c++ code in python using ctypes, boost.python, etc make your python application faster?
Suppose I am making an application in pygtk and I need some functions which need to be fast. So if I use c++ for certain tasks in my application will it be beneficial?
And what are other options to make python code faster?

Rewriting performance-critical parts of your code in C++ could be one option. To do this effectively, you first need to understand where the bottlenecks are. The best way to do this is probably to write everything in pure Python first, and then profile.
Another option might be to use PyPy.
Finally, if you find that the bottleneck is numerical computations, then NumPy is worth a look.
It is worth noting that if, for example, it turns out that your code is I/O-bound, then none of the above options are going to be of much help.

It depends, there's not a definitive answer. If you write bad code in C++ it could be even slower than well written Python code.
Assuming that you can write good quality C++ code, you can expect speedups up to 20x in the performance critical parts.
As the other answer says, NumPy is a good option for numerical bottlenecks (if you think in matrix operations rather than loops!); and SciPy comes with weaver, that allows you to embed inline C++ and other goodies.

Related

C++ Libraries to parsing [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm doing a software to generate animations for algorithms. These algorithms are written in an interpreted language, near to C (more or less a C-oriented pseudocode). Thus, my program must interprets algorithms written in these language. Also, this language will be incremented all the time to support more and more features. The key issue here is to search an library allowing increase the language easily and making easy integrate different parsers in the same program. The app is written in C++ licensed under GPL.
A object-oriented parser is my target solution indeed. I need help to choose a good library with this purposes. Also it's desirable the library is multiplataform and available in official repositories of commons distributions: Ubuntu, Suse and so on.
Actually, I know more or less well the next two libraries/tools:
Flex/Bison++: Both are Flex/Bison wrappers that allow generate C++ code instead of C code, and choose a name for your class. Problems: if you install Flex/Bison++, Flex/Bison are overwritten. I don't want to complicate users if they want compile my code. Moreover, CMake fails search the version number of the library. This can be solved manually, but isn't elegant.
Boost.Spirit: It doesn't have the previous problems and match with all desirable features I described above. But, I've read it isn't fine to parse big languages and to solve grammar ambiguities. Moreover, the compilation times are enormous. But, I love it can compose grammars in a constructive manner. This is very important to make the code/language/programm extensible.
What is your recommendation?

Why C++ can't be made as Python in terms of convenience [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
This question may seem to be naive.
But I think it'll be much worse if I don't ask it at all.
When a discussion begins about the features of Python that the developers love the most, they usually mention list comprehension, syntax relying on indentation (thus avoiding brackets, etc.) and some other.
At such moments I ask myself a question why there can't be made a language based on C++ but having a syntax like in Python and having all the features like list comprehensions, generators.
I understand that such a language won't have all the features that Python has, e.g. eval or exac statements (because they rely on Python being an interpreting language), may be some others that I don't know of.
But I also know that there is a project called Shedskin which makes a C code of a Python code (with some restrictions on what can be used in Python code).
So, are there some real reasons why it's impossible to create such a language that will combine all the best features of Python and a very fast code that produces C++? Or it's just the turn of events that Python for some reasons became very popular and it turned out to be interpreted, so a lot of people use it for its greatest features still discontent at the speed of the code, and some of them struggle to create something (like Shedskin or Psyco) to speed it up?
Google as created a language called Golang ( or Go). It is a compiled language with python like syntaxe. There are alot of video and documenttation that will answer your question there.

what is better to learn for pattern recognition? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
c or c++??
if i want to make a project on pattern recognition( artificial computing)
using c or c++
which one should i choose??
Object Oriented Programming can probably be of some help if you start programming something complex. That is possible with C but will probably be easier using C++. That said there is a risk to get lost on the multitude of features of the language if you are just learning it, and it's probably less so with C. But it's not so hard to use only a subset of C++, so definitely C++.
The most important point is that you should first focus on the problem(s) to solve before focusing on the tools you are using.
I would use something high level so you could learn about your own algorithms and not how to implement your algorithms. If you can write pattern recognition single handedly in C I applaud you. It is beyond my skill.
Perhaps Ruby or Python then implementing the computationally expensive parts in native C?
Since C++ is effectively a superset of C, there is no good reason not to use C++.
I think that is the least of your worries. C is available on more platforms, C++ has more features.

which one to choose for future , c++ or python2.x/3.x [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
since last four years i had been coding in c/c++, but those lenthy programs made me sick of them.
then i got to know about python, and i have learned the basics.
python seams to be more flexible and powerful than c++...
But i want to know is python realy better than c++?
if yes/no in what ways , please explain.
since i am a student , practicing which language would fetch me better job?
Python is completely different than C/C++, so it's hard to compare. Python lets you write clear, concise programs and very quickly develop software at the price of performance. It lets you be very productive and in many cases program performance is less concern, than programmer performance.
There are many existing programs for python 2.*, so it's better to stick for now with it. It would be fairly easy to move to 3.* later on.
It all depends on your needs, Python isn't replacing C/C++ in the embedded space anytime soon, and not too many web frameworks are going to be based on C/C++.
Python is neither better nor worse, or neither more or less flexible or powerful than C++. it's just aimed at a different set of problems.
I would rather students start at something like C++ so they have a better understanding of things like pointers & memory management. It's not really objects all the way down.

python challenge, but for C++ [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Does anyone know any site or book that presents problems like python challenge, but for C++?
When I think python challenge, I do not mean only a set of problems to be solved with C++ (for that I could probably use the same problems of python challenge), but rather problems that will probably be best solved using C++ STL, special features of the language, etc.
For example, there is one python challenge that is specifically designed to teach you how to use pickle, a serializing library for python.
Until now, I only know programming contests problems, but they could also be solved with C, java or other languages.
You might like to have a look at Herb Sutter's Guru of the Week series of articles.
Google Code Jam problems frequently have analyses with snippets of C++ code, probably because C++ is by far the most popular language used for solving code-jam problems. The latter also allows you to see many C++ constructs cleverly employed, as code-jam allows you to download the solutions by all the competitors. As most code is C++, you'll get to learn a lot of nice C++ tricks for efficient code.
There are many tasks on Rosetta Code that are not implemented in C++ as yet. Try your hand at those, especially if you can use advanced features (templates, external libraries, etc.) to produce a particularly nice solution. Remember that there is no fundamental reason why any of those tasks should be beyond the C++ language, and there's usually several other implementations in other languages to show you other ways to attempt the task, which can help a lot.
You're going to have a difficult time finding that because C++ provides less for you than almost any other language available. If C++ provides it, it's probably provided by Python or Java or C or any other programming language.
Why not try using some C++ concepts such as the STL to solve Project Euler problems?