Announcement

Collapse
No announcement yet.

Speed between PB35 and JAVA: HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Speed between PB35 and JAVA: HELP

    Hello
    I was testing a simple test program written in PB35 when a friend arrived.
    My friend told me he'll write the same program in JAVA to see the difference
    in speed of execution.
    Few days later the result is so great.My programs are 2.2 time slower than his.
    But why?
    His Java program takes 1.6 second on his computer.
    My program written for PB35 takes 6 seconds on his computer
    My program written for PBCC takes 3.5 seconds on his computer.
    When I run the three program on my computer the results are similar.

    Can any one help because I can NOT figure out what slows my program down.
    I suspect I did NOT declare the PUBLIC, PRIVATE correctly and also the DYNAMIC
    and STATIC arrrays.
    ====== The following is the JAVA PROGRAM =====
    /** Purpose: This program iterates through 5 nested loops and ultimately
    tells us how quick java (jdk1.2.2) is compared to PB35.
    * @author Nicholas Mitchell
    * @version 1
    * @date 5 January 2001
    */

    import java.awt.*;
    import java.util.*;

    public class Counter extends Frame{

    private int sum, counter1, counter2, counter3, counter4, counter5;
    private int num = 80;
    private int [][] myArray = new int[80][5];
    private int count;

    public Counter(){

    sum = 0;
    for (counter1 = 1; counter1 <= num - 4; counter1++){

    count++;

    for (counter2 = counter1 + 1; counter2 <= num - 3; counter2++){

    for (counter3 = counter2 + 1; counter3 <= num - 2; counter3++){

    for (counter4 = counter3 + 1; counter4 <= num - 1; counter4++){

    for (counter5 = counter4 + 1; counter5 <= num; counter5++){

    sum += 1;
    myArray[0][0] = counter1;
    myArray[0][1] = counter2;
    myArray[0][2] = counter3;
    myArray[0][3] = counter4;
    myArray[0][4] = counter5;

    } // end loop 5

    } // end loop 4

    } // end loop 3

    } // end loop 2

    System.out.println( sum );
    } // end loop 1

    }

    public static void main ( String [] args){

    Date t1 = new Date();
    Frame frm = new Counter();
    Date t2 = new Date();
    System.out.println( "Start: " + t1);
    System.out.println( "Finish: " + t2);

    }

    }
    ==========The following is the program ready for PB35 compiling ======
    ' Purpose: This program iterates through 5 nested loops and ultimatly
    ' tell us how quick this program runs when compiled in PB35
    ' author: Guy North
    ' Date: 18 December 2000
    CLS
    DEFINT C, D, N, M
    DEFLNG S
    S&=0
    Time1 = TIMER
    Num = 80
    DIM MyArray(Num,5)
    FOR Counter1 = 1 TO Num -4
    FOR Counter2 = Counter1 + 1 TO Num -3
    FOR Counter3 = Counter2 + 1 TO Num -2
    FOR Counter4 = Counter3 + 1 TO Num -1
    FOR Counter5 = Counter4 + 1 TO Num
    S& = S& + 1
    MyArray(1,1) = Counter1
    MyArray(1,2) = Counter2
    MyArray(1,3) = Counter3
    MyArray(1,4) = Counter4
    MyArray(1,5) = Counter5
    NEXT Counter5
    NEXT Counter4
    NEXT Counter3
    NEXT Counter2
    PRINT S&;" ";
    NEXT Counter1
    Time2 = TIMER
    PRINT: PRINT " to fill an array 80 by 5 .... ";S&;" times"
    PRINT " With this computer it took"
    PRINT " ";Time1
    PRINT " ";Time2
    PRINT " "; ROUND((Time2 -Time1),0);" seconds"
    DELAY 10
    END
    ========== The following is the program ready for PBCC compiling
    ' Purpose: This program iterates through 5 nested loops and ultimatly
    ' tell us how quick this program runs when compiled in PBCC
    ' author: Guy North
    ' Date: 8 January 2001
    ' Compiled with Consol compiler PBCC version 2.00
    DEFINT C, D, N, M
    DEFLNG S, T
    FUNCTION PBMAIN() AS LONG

    CLS
    S&=0
    Time1 = TIMER
    Num = 80
    DIM MyArray(Num,5)
    FOR Counter1 = 1 TO Num -4
    FOR Counter2 = Counter1 + 1 TO Num -3
    FOR Counter3 = Counter2 + 1 TO Num -2
    FOR Counter4 = Counter3 + 1 TO Num -1
    FOR Counter5 = Counter4 + 1 TO Num
    S& = S& + 1
    MyArray(1,1) = Counter1
    MyArray(1,2) = Counter2
    MyArray(1,3) = Counter3
    MyArray(1,4) = Counter4
    MyArray(1,5) = Counter5
    NEXT Counter5
    NEXT Counter4
    NEXT Counter3
    NEXT Counter2: PRINT S&;" ";
    NEXT Counter1
    Time2 = TIMER
    PRINT: PRINT " to fill an array 80 by 5 .... ";S&;" times"
    PRINT " With this computer it took"
    PRINT " ";Time1
    PRINT " ";Time2
    PRINT " "; ROUND((Time2 -Time1),0);" seconds"

    WAITKEY$

    END FUNCTION
    =============END ===========

    ------------------
    Private Website:
    Guy's Website -
    Brisbane, Australia

  • #2
    Please see my comments in your crosspost in the PBCC forum.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment

    Working...
    X