A
A
artmel2016-03-01 16:26:30
C++ / C#
artmel, 2016-03-01 16:26:30

Language selection for multithreaded application under linux?

I have never written in applied languages, but the task was to speed up the application written in php. satisfied with everything except speed. math problems, public key encryption, multiple regular expressions over text over 1mb.
You need to select a language. in addition to speed, the number of lines is also important for writing the same problems. For it does not smile to write instead of 1 line in language X, to write 5 lines in language Y, with a performance difference of 30%.
Will work on linux, most likely debian. The number of processors is up to 4, and the cores are 8 (or more) per processor.
A program will be called from php that will parallelize the task and create threads according to the number of cores.
simultaneous launch of the program by two php scripts is unlikely.
accordingly, in this language it should be convenient to work with threads for different cores.
The choice is between c , c++, java . also any of your options.
If it is possible to rewrite it into your language and compile the exe under win32, I will be grateful. This will help determine the speed of execution.

$tocnost =Pow(10,7 * -1);
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$n=0;
$s1=0;
$s2=0;

$time_start = microtime_float();
do {
    $n=$n+1;
    $S1=$S2+4/(2*$n-1);
    $n=$n+1;
    $S2=$S1-4/(2*$n-1);
} while (($S1-$S2) > $tocnost);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo " $time seconds";

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nirvimel, 2016-03-01
@artmel

C - Pros: The ability to squeeze the maximum speed out of iron.
Cons: When migrating from dynamic scripts (of the type mentioned in the question, PHP) can be somewhat shocking in its verbosity and the need to explicitly describe every little thing that is implicit in other languages.
Java - Pros: Automatic garbage collection makes life a lot easier and alleviates the shock of migrating from dynamic scripts. Ingenious JIT - allows you to reduce the lag behind bare metal in speed (at best) up to 30% -50% (compared to the lag at times and tens of times for dynamic scripts).
Cons: To take advantage of the full power of the JIT, you need a deep understanding of how it works and the rejection of the use of objects (the main feature of Java) in the depths of the most loaded loops.
C++ - Different people use it differently. Someone writes in C style on it, gets the speed of pure C and the contempt of true C ++ owls. Someone writes on it in the Java style and gets a more compact code, but also the speed of Java. In fact, it is possible to write beautiful, elegant, and as fast programs in this language, but it will take years of training (this is not about the syntax of the language and not about the standard library).

A
Alexander Shpak, 2016-03-01
@shpaker

You can look at Go...

M
ManWithBear, 2016-03-01
@ManWithBear

You can look towards Swift'a.
UPD. In any case, all these studies in a vacuum are useless. Select one task, do it in different languages, run tests. Choose the one that best suits your needs.

A
artmel, 2016-03-02
@artmel

in general, c++ is chosen, for a banal reason. many textbooks and many who write on it.
well, relatively many.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question