Best way to show speed?

This is a discussion on Best way to show speed? within the C Programming forums, part of the General Programming Boards category; I'm doing a little experiment to test the speed difference between a C app and a Java app. I'm not ...

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    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;
    }

  2. #2
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131
    Yes.... It is really best way..to show speed.Good Work.
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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]
    Last edited by Shiro; 11-17-2002 at 04:12 AM.

  4. #4
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    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.

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    Big O isa good way to measure speed and complexity. Do a search on it, its complex but accuarte
    Monday - what a way to spend a seventh of your life

  6. #6
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    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.

  7. #7
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 12:29 PM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 12:40 AM
  3. Replies: 6
    Last Post: 01-08-2006, 02:49 PM
  4. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 07:05 AM
  5. Can anyone here speed read?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-07-2003, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21