Java실행 시간 계산

        long startTime = System.currentTimeMillis();
        int k = 0;


        for (int i = 0; i < 1000000000; i++) {
            k = k + 10;
        }


        long endTime = System.currentTimeMillis();


        System.out.println(“시작시간 : ” + startTime);
        System.out.println(“종료시간 : ” + endTime);
        System.out.println(“소요시간 : ” + (endTime – startTime));
        System.out.println();
        System.out.println();
       
        startTime = System.currentTimeMillis();
        k = 0;
        for (int i = 0; i < 1000000000; i++) {
            k += 10;
        }
        endTime = System.currentTimeMillis();


        System.out.println(“시작시간 : ” + startTime);
        System.out.println(“종료시간 : ” + endTime);
        System.out.println(“소요시간 : ” + (endTime – startTime));

==============================================================
시작시간 : 1284097698269
종료시간 : 1284097698971
소요시간 : 702



시작시간 : 1284097698971
종료시간 : 1284097700017
소요시간 : 1046

Leave a Reply

Your email address will not be published. Required fields are marked *