Menghitung Waktu Eksekusi Program di Java dan C


Method yang digunakan adalah:

Java: System.nanoTime();

C: clock();

Java

</strong>
<pre>/**
 *
 * @author windu purnomo
 */
public class RunTime {

    public static void main(String[] args) {
        double start = System.nanoTime();
        int l = 0;
        for(int i=0; i<1000; i++){
            for(int j=0; j<1000; j++){
                for(int k=0; k<1000; k++){
                    l++;
                }
            }
        }
        double finish = System.nanoTime();
        System.out.println("waktu eksekusi program: "+(finish-start));
    }
}


Download RunTime.java

C

#include <stdio.h>
#include <conio.h>
#include <time.h>

main(){
       int a, b, i, j;
       double start = clock();
       for(i=0; i<10000; i++){
          for(j=0; j<10000; j++){
              for(a=0; j< 1000; j++){}
          }
       }
       double stop = clock();
       printf("waktu eksekusi Program: %f", (stop-start));
       getch();
       return 0;
}


Download RunTime.c

About windupurnomo

I'm interested in programming. I am active with several programming such as Java, C #, C, JavaScript, HTML. I'm also develop desktop application (Java Swing), Mobile Application (Android), and Web programming (ASP MVC).
This entry was posted in Java, programming and tagged , , , , , . Bookmark the permalink.

3 Responses to Menghitung Waktu Eksekusi Program di Java dan C

  1. kalau boleh tau, satuan dari waktu komputasinya itu apa ?
    milisecond, atau ?
    #mohon pencerahannya..

  2. Laxuz says:

    nanosecond

  3. abdu says:

    mba, maksudnya script ini apa?
    for(i=0; i<10000; i++){
    for(j=0; j<10000; j++){
    for(a=0; j< 1000; j++){}
    }
    }

    kenapa i harus < 10000?
    runtime ini dalam detik atau milidetik atau microdetik?

    Terima Kasih

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s