Higher Level Languages ​​with C Functions

It may have been asked before, but I could not find it. My question is simple: does it make sense to write an application in higher-level languages ​​(Java, C #, Python) and time / performance functions in C? Or at the moment, if you do not perform very low-level programming of the OS / game / sensor, is it still necessary to have a complete, say, Java application?

+7
performance c
source share
8 answers

It makes sense if you a) notice a performance problem, and b) use performance measurements to determine where the problem occurred, and c) cannot achieve the desired performance by modifying the existing code.

If any of these elements are not applied, it is probably a premature optimization.

+7
source share

If you are fluent and productive in a higher level language such as Python and Lua, then you should definitely start writing in that language. Look for bottlenecks if and when they exist.

+3
source share

Usually, your preferred language will do everything you need in an acceptable time (er, trying fast).

Of course, critical functions of time / performance can be written in a “more optimal / suitable” language, such as C or assembly - but whether this will actually do something faster is another story. There are laws that determine how much actual / total acceleration you get, in particular Amdahs Act and (decrease in profits) .

To answer your question, it makes sense to rewrite these critical functions in lower languages ​​if there is high enough speed to guarantee extra work.

+1
source share

speed can be very similar to things like c #.

What is the complexity of latency. Therefore, if you want to write something that you know is 10 ms, then C is predictable enough (ignoring any variability your operating system has to offer).

Having said that for very dense long loops (like for image processing) things like C / C ++ can speed up a bit. You can get reasonably reasonable performance from C #, you need to be careful how you program it, but I found in general, you can still squeeze more out of C / C ++

+1
source share

I suggest you read Cliff Click excellent Java vs. C Performance .... Again. . It describes many of the comparison points between Java and C ++.

As expected, the conclusion is that it depends, but it is worth reading.

0
source share

You can only answer this in each case and without reference to what you are doing, it is impossible to answer.

But it is possible that what you really want here is some kind of sanity check to make sure this approach is not crazy. I worked on tools ranging from a very large graphical application (~ million lines) to relatively small physical simulators (~ 10,000 lines) that were written in the same way as you describe: Python outside for the interface (both for the API and for GUI), C / C ++ on the inside for heavy lifting. They all took advantage of this division of responsibility.

0
source share

This is especially important for scripting languages. Things that come to mind are games made in Python. In most cases, Python is too slow for some of the more crunchy aspects of games, and they make it a C-module for speed. Make sure you really need speed, and this crunch number is a performance bottleneck, not a general algorithm. Doing brute force searches on a list will be slow in both C and Python.

0
source share

I would say that it depends a lot on your application. What performance is important? short start time? high bandwidth? low latency? Is it important that response times are always predictable? Is the application short-lived or does it run for long periods of time?

Java can give you high throughput, but sometimes short frosts in garbage collection. C # is probably similar. Python, well, performance there will often lag behind the rest for everything that is not written in C (some things are written in C, even if you did not do it yourself).

So, as others said. It depends.

But as always with performance: first measure, optimize when you know what you need.

0
source share

All Articles