-
Best way to show speed?
I'm doing a little experiment to test the speed difference between a C app and a Java app. I'm not sure what the best way is to display true speed. Should I have the apps perform certain calcs a number of times and find the difference in seconds? Here is what I have so far. It completes in about 50 seconds on my development box.
Code:
/*
Display the speed of C.
*/
#include <stdio.h>
#include <time.h>
long startTime, endingTime, totalTime;
void showTheSpeed(int loops)
{
int i;
startTime = time(NULL);
for(i = 0; i < loops; i++)
{
printf("%d \n", i);
}
endingTime = time(NULL);
totalTime = endingTime - startTime;
printf("Completed %d loops in %d seconds. \n", loops, totalTime);
}
int main()
{
showTheSpeed(1000000);
return 0;
}
-
Yes.... It is really best way..to show speed.Good Work.
:D
-
Comparing speed of C, C++ and Java or other languages is hard and in my opinion impossible. There are several research projects done to do this, some result in C is faster than Java, others result in Java is faster than C. This really depends on the applications which were created to compare the speed, it also depends on the used tools (compilers etc.) which are used.
An example of such a project:
http://www.cs.vu.nl/~rob/papers/hpcn01.pdf
[edit]
At our company we're creating embedded systems, we did some projects with Java and found that using a JIT, the Java code was as fast as a similar C++ application. But note that it were just these applications, I can imagine that in other applications the C++ implementation would be faster.
The main disadvantage of Java is the garbage collector, which has unpredictable behaviour (it just starts running when it thinks it is necessary to collect garbage), which is why Java is not suitable for real-time systems.
Some other articles:
http://www.onjava.com/pub/a/onjava/s.../embedded.html
http://www.circuitcellar.com/pastissues/ articles/Vlad102/vlad102.pdf
[/edit]
-
I think your example is mainly just going to show the speed of the print statement.
But then again it's really not possible to accurately compare the speeds of everything.
-
Big O isa good way to measure speed and complexity. Do a search on it, its complex but accuarte
-
Big-O is only used to compare different functions, not different languages or programs
if he uses Big-O the speed will be the same for both because he is implementing the exact same algorithm in two different languages.
-
Another problem with your testing is that it is testing the speed from within the program, but most of the problem with java is the large amount of setup time before the program even runs
I would recommend making a separate c program that starts the timer, then runs the program by calling system("programname");
then stopping the timer
and run this program numerous times for each program you are testing.