Question

Could any Python program be made faster if you instead wrote the same program with C++ and made it as optimized as possible?

Attached: 1658610812108247.png (432x324, 87.18K)

Other urls found in this thread:

docs.python.org/3/extending/extending.html
twitter.com/SFWRedditImages

Attached: VirtualBox_TOS_03_08_2022_19_48_54.png (640x480, 16.58K)

Yes

Sometimes people use Python to solve mathematical problems and it takes a long time to compute. I wonder how much the computing time would be reduced if you instead used C++ for those kinds of problems.

Probably less than the additional time required to write the program in c++

unlikely, unless this includes learning C++ in the process.

Would it require a lot more code? I saw one video where a guy waited for a month for his Python program to finish. If you could reduce that down to one day or something with C++ I think writing more code would be worth it.

depends entirely on the problem and what libraries you use or don't use. also if the python solution was already using numpy and big vectors for everything, you shouldn't expect any big gains.

The answer is yes but it comes at the cost of taking longer to write and in C++'s case also a longer compile time.

No, because I'm a shitty programmer and rely on other peoples modules.

C++ afaik doesn't have libraries that help you solve your entire problem in one line, unlike python. Also the more stuff you use like numpy the harder it'll be to optimize since numpy is already carefully tuned for performance.

In theory any program that runs any python code could be optimized with c++ since python code is parsed at runtime and interpreted

is this bait?

shit colors

Yeah but it probably saves time in the long run, since python has to re-interpret it every time it's run. And think about the energy savings.

yes, it can. In fact, every single python program can be made faster this way. By a massive margin too. But then you realize you have to write C++ and you're back to square one. The whole point of python was to avoid that and avoid compiling for a specific platform, cpu, and architecture.

the cost of computational power is negligible when compared to the cost per hour of the people who use python to solve mathematical problems professionally

Usually they will use libraries like numpy, scikitlearn, or tensorflow. These are all written in C++ for performance and called by python.
You can even easily integrate your own C bindings into python if you have a performance critical segment of code:
docs.python.org/3/extending/extending.html

Just use C++ at that point

Attached: FWSNfO-UEAAd658[1].jpg (2048x1918, 407.93K)

Yeah you would gain 1 second on the high level Python parsing and 0 seconds on the month of calculation that was already running C code.
And that's assuming you actually know how to program for HPC. I find that a lot of people who want about low level programming have no idea about how to use different levels of parallelism and simd instructions.

>C++
Numpy backend is written in C. Sklearn is written in C and Cython. Only Tensorflow is written in seeples.

>the cost of computational power is negligible

It's negligible only if you're only dealing with small amounts of data.

having a supercomputer run for few hours will always cost less than paying a programmer to rewrite code.

go ahead, try doing a simple 5*5 matrix multiplication in Cpp vs python, python will be done running before you encounter your first segfault

>virtualbox
run it on bare metal like a real man