Are you running C++ in release mode or in debug mode?
Anyway, a language's speed is not proven by printing characters. What exactly happens when you print them can be system-specific, compiler-specific, etc.
If you're really interested in the speed differences, you should look up some well setup benchmarkings on the internet. They'll probably give you a way clearer image!
I've only done a few little programs where I've done comparable things in both Python and C++. Like the others have said, print statements are not a good measure of a language's efficiency. Dynamic languages are inheritantly slower than compiled.
I remember making a large-resolution PNG image of the mandelbrot fractal using both PyPNG and C++ LodePNG libraries. Not only did PyPNG crash at larger resolutions, it was significantly slower than C++ at calculating each pixel. I hadn't tried Python's PIL, but I'm sure it's a similar story.
I understand that compiled languages are faster than interpreted languages. But why is Python faster at this particular situation? is it because Python's print functions requires less processing?
Also, what's the difference between Debug mode and Release mode? and how do I change these options in command prompt using g++?
- -std=c++11 means processing the input files according to the C++11 standard.
- -O3 means the third level of optimisation, i.e. more speed over executable size.
- pedantic-errors means to follow the standard 'pedantically', and throw errors instead of warnings
As for the 'print' statements... generally they are not a good measure of a languages speed, becase normally it is not the generated code that is the bottleneck, but the actual printing process. Also, you'll probably find that the Python code for 'print' is actually written in C anyway.
A better way to test language speed for these kinds of things would be scientific or mathematical number-crunching of some kind.
And yes, clang++ is the C++ frontend of the LLVM compiler. I prefer it to the GNU compiler g++, but they both generally work fine.
They are necessary to make sure that a diagnostic is issued for non-conforming program constructs if the International Standard for C++ requires that a diagnostic must be issued for that incorrect construct (and where g++ conforms to this requirement by the standard).
> because I don't want to use too much options...
Most shells support command history and command aliases.
GNU make is the first tool on the path from command history to fully integrated build systems.
The "Debug" and "Release" builds are terms used by Microsoft's compiler. It will generate entirely different code in those two modes. The GCC and Clang have a large selection of options for both optimization and debugging that each (may) change the produced code, and rather than deciding "debug OR release" you tell them "how much".
The GCC and Clang have a large selection of options for both optimization and debugging that each (may) change the produced code, and rather than deciding "debug OR release" you tell them "how much".
You can do that with VS, too... the whole Debug/Release interface is just a simplified way to switch between two common build configurations. But you can add additional build configurations and tweak settings for each of them individually.