কম্পিউটার

পদ্ধতির এক্সিকিউশন সময় গণনা করার জন্য জাভা প্রোগ্রাম


এই প্রবন্ধে, আমরা বুঝতে পারব কিভাবে পদ্ধতিগুলি কার্যকর করার সময় গণনা করা যায়। কার্য সম্পাদনের সময় শেষ সময় এবং শুরুর সময় বিয়োগ করে গণনা করা হয়।

নীচে একই -

এর একটি প্রদর্শন রয়েছে৷

ইনপুট

ধরুন আমাদের ইনপুট হল −

Run the program

আউটপুট

কাঙ্খিত আউটপুট হবে −

The program is being executed:
The Execution time of the program is: 620872 nanoseconds

অ্যালগরিদম

Step 1 - START
Step 2 - Declare 3 long values namely my_start_time, my_end_time and my_execution_time.
Step 3 - Start time of the program is recorded using the function System.nanoTime() and assigned to variable my_start_time.
Step 4 - Similarly end time of the program is recorded using the function System.nanoTime() and assigned to variable my_end_time
Step 5 - Total execution time of the program is calculated by my_end_time - my_start_time. Store the value in my_execution_time.
Step 6 - Display the result
Step 7 - Stop

উদাহরণ 1

এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।

public class Main {
   public static void main(String[] args) {
      long my_start_time, my_end_time, my_execution_time;
      my_start_time = System.nanoTime();
      System.out.println("The program is being executed:");
      my_end_time = System.nanoTime();
      my_execution_time = my_end_time - my_start_time;
      System.out.println("The Execution time of the program is: " + my_execution_time + " nanoseconds");
   }
}

আউটপুট

The program is being executed:
The Execution time of the program is: 129621 nanoseconds

উদাহরণ 2

এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।

public class Main {
   public static void main(String[] args) {
      long my_start_time, my_end_time, my_execution_time;
      my_start_time = System.nanoTime();
      int my_input_1 = 100;
      int my_input_2 = 250;
      int my_sum = my_input_1 + my_input_2;
      System.out.println("The program is being executed:");
      my_end_time = System.nanoTime();
      my_execution_time = my_end_time - my_start_time;
      System.out.println("The Execution time of the program is: " + my_execution_time + "  nanoseconds");
   }
}

আউটপুট

The program is being executed:
The Execution time of the program is: 103801 nanoseconds

  1. একটি বৃত্তের পরিধি খুঁজে পেতে জাভা প্রোগ্রাম

  2. জাভা প্রোগ্রাম একটি ট্রাপিজিয়াম এর এলাকা খুঁজে বের করতে

  3. একটি আয়তক্ষেত্রের পরিধি খুঁজে পেতে জাভা প্রোগ্রাম

  4. রাউন্ড ট্রিপ টাইম (RTT) গণনা করতে পাইথন প্রোগ্রাম