C # and C, C , D, Java performance comparison (3)
(Article transferred from http://mag.vchelp.net) jason
F2i will not talk about Intel, it can be seen that the efficiency of C # in the floating point to integer is much higher than the remaining four, only C, C , and D overhead 2/3, is 2/5 of Java. Before I let them use the same random number generator, the performance difference between different languages is very large, this shows that the conversion speed is very dependent on the specific floating point value. Of course, this is to see. To ensure that each language is the same conversion, the program calculates the sum of the conversion value, which also helps any excessive optimization to remove the entire loop. It can be seen that this conversion is different in the correctness of the language. The sum of each language is equal to 10,000 results in Table 3. They indicate (although it cannot be confirmed) C, C , and D are the most correct, Java second, C # is the worst. C # sacrifice correctness and reduces processor floating point accuracy (see quote) exchange for superior performance is convincing, but in fact, I need more evidence before doing this. As for Intel, it is fair to say that its performance is more excellent.
5 languages are quite efficient here. The other 4 performance is 5% lower than C # low. The only thing interested is that these four languages are slightly better than C #. This indicates that C # does low in efficiency, although only a little lower in this area. This is opposite to the results of integer to floating point conversion. Similarly, it is worth noting that although Java is very low in floating-point to integer, it is the best in the conversion of the floating point, 10% higher than C # height. For F2i, Intel performance is excellent, and C and C use only 10% and 23% of C # time, respectively.
I2Str is interspentable to character type conversion. C # is slightly slightly prinTf, C and D. High conversion efficiency based on iostream than C is high. It is 4 times that of C # runtime (5 times for Intel and VC6 STL / CRT). However, Java has excellent performance and uses C # 2/5 time. Because C is inefficient, the second variable uses Stlsoft's Integer_TO_STRING <> template function. It is faster than all available conversion mechanisms than C and C libraries on many compilers. In this case, the performance is 10% higher than that of C #, which is about 20% higher than C and D. But because of the optimization of the Intel compiler, INTEGER_TO_STRING <> seems to find its perfect partner: 5% higher than C #, is the third speed exceeding Java, more than 17 times faster than iostream. It is considered to be close to the upper limit of conversion efficiency.
The conversion result of Str2i characters to integer is in front of the front. C and D are more than 5-8 times faster than C #, three times faster than Java, and the Java is much higher than C # efficiency. But these four conversions based on iostream are fast than C . C uses DIGITAL MARS / STLPOR Run Time T is 2.5 times the C #, 10 times with Intel and VC6 CRT / STL. This is another deadly weakness of iostream. However, it is said that C efficiency has not been lost. (In fact, I am writing characters to the Stlsoft library to integer to match the outstanding conversion performance of its integer_to_string <>. The initial results show that it will be better than C ATOI, so C in this conversion is also better than C. I hope to complete this conversion before publishing this article. Please refer to http://stlsoft.org/conversion_library.html.)
Picalc is similar to each language performance here. C # and Java are almost the same, 10% higher than C, C efficiency. The performance of C # can explain this: its floating point number has high operational efficiency, which can be seen from F2i. But this can't understand the performance of Java. We can think that C # and Java can optimize the loop, which relate to function calls, but this depends on in-depth research. Since performance is within 10%, we can only draw this conclusion: the differences in circulating structural performance in various languages are not significant. Interestingly, Intel's optimization is not practical, it may be because the PI value is calculated too simple. PicalCr: The results here can be more determined that the performance deviation of C, C , C # and D languages is within 2%, which we can speak fairly what they are in the performance of recursive execution. Java is spending more than 20% of other four languages, plus JVM (Java virtual machine) in stack consumption during more than 4,500 recursive, which can significantly get Java processing recursive from speed and memory consumption. Intel's optimization capabilities have significant roles here (10% impressive), but I have not analyzed this in detail here.
SIEVE: Algorithm for relatively simple computational rigidity (only included iteration and array access) Description C, C , C # and D language in this regard (only 0.5% deviation), but Java has a low performance of 6% . I think this is a large article, C, C code does not perform array boundary security check, while C # and Java perform array boundary check. I explained this result is that the C # and D language can optimize the boundary check according to the condition test of the array boundary in the FOR cycle, while Java is not. Since C # is an emerging language, D language has not been issued, which is not so disappointed. Even if this is not just a Java, it will not be impressive. Besides, Intel optimization has a significant role - growth of 5% performance, as PicalCr examples, which is more impressive relative to other languages.
STRSWTCH: This test is not very good for C # languages. Even C inefficient string operators = = are 2.5 times faster than C # ("Digital Mars) to 5 times (Intel VC6 STL / CRT). The string in the .NET environment is internal processing, which indicates that the string is stored in the global discrete table, and the copy can be eliminated from the memory, and the equivalent test is performed in a consistent check (as long as the two parameters are internally) ). This apparently indicates that the internal repair mechanism is more efficient or consistency check does not establish a "string-swatch" mechanism for C #. This serious low efficiency of C # is more forever, because it is not a good reason to explain why this is. As in Example 8, the string instance of the variable 1 is text, which is inside (in fact, there is no limit in Example 8, and the verification parameters used in the pre-cycling of the variable 1 are truly internally of).
When the consistency check is performed in the variable 2, it is found that only Java's performance has significantly improved, from 2% to an impressive 30%. Obviously, Java is unrealistic in using consistency check because it cannot limit the string in a real program. However, this can be used to illustrate a performance of the language that supports internal processing and providing programmable access to such a mechanism. Ironically, C # is one of these five languages, and its performance is the worst. STRCAT: Table 2 shows five languages for each of the five languages in this example in a microsecond (μs). This article does not have enough space to detail the 17 execution code, but try to maintain the true appearance of the four variables of Example 7. Variables 1 and 2 In all language execution code involves a stack-based string memory, while C, D language in the third variable, C, C , D language in the fourth variable in structure memory, this is Some degrees description their performance is better than other variables and language execution code. The discussion of this example C, C is suitable for the Digital Mars version, because the performance of the Obvious Intel is enhanced by the efficiency of the Visual C runtime library (non-desired), in fact, each test of Intel Differences than Digital Mars.
The first test is performed by default, it is clear that the performance of C # and D languages is better than other languages. It is very strange that Java's performance is the worst because Java is considered to be capable of explaining a string sequence into a string component format in a statement (manually converted in variable 4).
The second test, it is well known that its format is not good, discloses a lot. Its inferior is different depending on the language. For C #, D and Java, it is included in a continuous expression, not like the first variable in an expression. For C, it simply omits the memory request before starting multiple connections to reassign. For C , it uses strstream and insert operators instead of using the str :: string and () operators. The results show that all languages reduce performance varying degrees. The additional polling of the C memory distributor does not have much effect, which may cause memory debris because there is no competition thread, so consume the same memory block. C changes into iostreams to make the code more compact, but there is no transition to the digital part, they are only inserted into the flow, and the expected execution results have verified this. D Because this change has reduced performance (32%), Java is more (60%). It is very strange that C # performance is only low here, less than 7%. This is very impressive, meaning that the alarm of the code check in the .NET's development environment will decline due to the Java string connection.
The third test uses Printf () / format () variables insufficient. By using partial / all of the frame memory, C, C , and D reach a good performance. The strange thing is that C # performance is only 22%, it is not worth mentioning. Java does not have this convenience. (It is also not worth mentioning in individual opinions) C # and D language can optimize their critical inspection in the closed loop in the closed loop.
Maximum test - hardcoded performance - this is a very interesting problem, because C can provide super performance, if you can encode the exact area of the problem, even if other languages (C #, Java) use default or performance optimization The same is true for components or ideas. Use their respective StringBuilders on C # and Java to provide real effects to achieve the best performance in this collection. However, C # can play the best efficiency, or cannot be compared to C / C , D language. Worse, the best performance of Java is poor than the most language of other languages, which is quite sad. In short, we say that the language of the direct operation can win those transformation works well or completely in the middle code, and obviously provide good performance, language usage is important to Java, and C # is Not important. Please pay attention to this.
STRTOK. TABLE3 shows the total time (units in milliseconds) in five languages. At the same time, their space is not mentioned in this article, but the implementation of all languages is very straightforward and is very obviously close to the essence of the four issues listed in Listing9. Like STRCAT, the results of the Intel compiler are not discussed based on the same reasons.
The first question - segmenting characters, retain space - Show C version is a significant winner, D language is slow 20%, C # is 3 times. Obviously, this relationship with the characteristics of the library is more obvious than language.
And I use Tokenizer than the famous Boost, then, the D language is 2 times faster than C , and C # is only 20% slowly. Even so, Stlsoft's Tokenizer is free, I think we should take this as a victory of C . (In fact, Template uses STL's Basic_String
Second issue - Segmentation Character, remove space - contains all languages implementation versions. Naturally, the C language has won the game, which uses a strTok () function, this function does not assign memory when creating tokens and directly writes the end of the end of the end of the tokenized string. Despite these unfavorable conditions, C performance is still very good, and time is 221% of C, it is better to D language, 432%.
C # and Java are very poor, 746% and 957%, respectively. This is simply can't believe, C # and Java running time is 3.4 times and 4.3 times of C , and these three languages are allocated to TOKENS. I believe this is that the STL model is more efficient than the PAssing Around Arrays while processing iTERABLE Sequences. (Please note that we have a high confidence. This is a comparison between C , C # and D language. I have written three Tokerizer's implementation, it is open, it can be obtained.)
The third question - divide the sentence, retain space - show two things. First, in these three languages are more expensive than achieving a single character than achieving individual characters. Second, we found that D language replaces the best performance of C , leading about 5%. C # continues to be smashed, probably 1.8 times the time in the other two languages. Fourth question - Segmentate sentences, remove space - no accident, C and D have probably consistent performance. C # is better (about 2 times the performance gap) Java slower (almost 3 times time). For C , C #, and D, the empty grid is removed, which does not drop the air, resulting in a small performance loss. Obviously, in C #, this is better than the other two losses. Very valuable is that these features are already implemented in C # and D. Since the array is not variable in C #, returning from TOKENS An array without spaces will result in reassignment. However, D allows the length of the array, which can dynamically adjust the size of the array This is a good example for D language provides better efficiency.
In general, considering performance and freedom, we can say that C is a winner, D is very close to the second place. C has the best performance, but only supports a type of tokerization. C # performance is very poor, Java is even more.
to sum up
We can divide the results into three situations: these include the characteristics of the language, including the characteristics of the library, or both. These only related features are displayed in F2i, I2F, Picalc, PicalCr, And Sieve Scenarios, which is very small in language choice. C # looks the best in general, but it is a bit not convinced that its excellent performance achieved in F2i is due to sacrificing floating point accuracy. (This requires more inspections, I will do it in the next article.)
Java is clear and worst.
When discussing the depth optimization effect of the floating point calculation of the Intel compiler, it is clearly displayed, C and C can do better than C #. I discussed this is not to say that these languages must be better efficient, but they can provide better optimization and enhance opportunities than other languages. This is probably unsatisfactory with this topic, C and C have more compilers than other languages; more competition, smarter people have different strategies and technologies. The operation target of the compiler is the processor, which will result in dramatic effects; we only explore this huge problem on the surface, but I will soon returned to this topic in future articles.
The STRTOK is the only one that can be said to be Library-Only, and C # is not good at this point. Although it is fast than Java, it is 2 times longer than other languages. It is also disappointing that Visualc / C run libraries. At this point, the effects of language and libraries are I2STR, STR2I, STRCAT, and STRTSWTCH, which is not very clear. C # is obviously much better than Java in the String splicing, but it is obvious than other differences. About Dear C, C , D, just on some links, quite right at another part.
It is very interesting that custom C library replacement plus depth optimized Intel's compiler.
In short, it is impossible to make quantitative conclusions. From the surface of the language, C # and Java are very simple, but the inefficient library reduces speed. I think that when the relevant library is not as good as the language itself, C # has a weak advantage; but in turn, when the library is gradually improved, it will be obviously not in the language itself. But still can see a little hope: C # is still possible to achieve the expected goal, because the library is easier to implement assembly. However, people think that because of the language compared to other languages, the library used by C # and Java is more closely coupled, and these libraries can be used as the key to these two language efficiencies, and at least the current version is like this. As I have made (from integers to characters) and related (from characters to integers), some people may not comply with the original intention of this article.
More in-depth discussion
This article mainly explores the "threat" that C # to C and Java may cause. In general, although this result is not encouraging, it is enough to surprise. In terms of efficiency, C # follows C and C these past similar products (if they are more efficient) can only be considered generally, at least in the comparison of basic language features. This is also the case to some extent, Java is also true. (I admit that I can't prove the absolute advantage of C and C relative to C #. During many years ago, during the analysis of our graduation thesis, I realized that the result of positive and exciting results, but the former spent smaller Economic expenditure.)
The above conclusions are not necessarily applicable to multiprocessors and (high performance file / network processing systems). However, this is really a good demonstration of the basic efficiency of these languages and the most basic libraries dependent on more complex operations.
As far as D development conditions, now make such a category seems to be too early, but it is really good. D's efficiency is at least C # 167%, in fact, most cases. Some people pointed out that it is only in the character era, and only a few people can complete a compiler and their attached libraries. I guess that D may develop into a powerful technology.
As far as I personally, as a person holding a prejudice against C #, it is accidentally surprised to its performance. I enthusiastically extended the performance of comparison analysis to more fields: complex and efficient memory applications, multi-threaded, process communication, special file processing, handwriting code overhead, these technologies can make language more Deep research. Can you see how interrogate is customized C library (such as cruntiny; refer to http://cruntiny.org/) and STL (such as stlport).
Thank you
Thanks to Walter Bright to provide me with an introduction to D. and timely pointed out some of the advantages that I have ignored at the time, so that I can improve the test engineering. At the same time, I would like to thank Sun Microsystems' Gary Pennington, which provided me with information on Java. There is also SCOTT PATTERSON, and he has a large number of drafts in this paper, and a detailed inspection of the full article.