Is there a way to assess/measure the efficiency of code in java -


for instance, have 2 versions of simple count loop - both achieve same thing 1 more efficient (and presumably uses less memory) other. see below:

code 1:

int num; (num =0; num<10; num++){ system.out.println(num); } 

code 2:

for (int num=0; num<10; num++){ system.out.println(num); } 

they compile identically , have identical performance , memory requirements.

for proof @ compiled java byte code using javap -c <classfile>

code:

public static void a() {     (int num = 0; num < 10; num++) {         system.out.println(num);     } }  public static void b() {     int num;     (num = 0; num < 10; num++) {         system.out.println(num);     } } 

byte code:

public static void a(); code:    0: iconst_0          1: istore_0          2: goto          15    5: getstatic     #15                 // field java/lang/system.out:ljava/io/printstream;    8: iload_0           9: invokevirtual #21                 // method java/io/printstream.println:(i)v   12: iinc          0, 1   15: iload_0          16: bipush        10   18: if_icmplt     5   21: return          public static void b(); code:    0: iconst_0          1: istore_0          2: goto          15    5: getstatic     #15                 // field java/lang/system.out:ljava/io/printstream;    8: iload_0           9: invokevirtual #21                 // method java/io/printstream.println:(i)v   12: iinc          0, 1   15: iload_0          16: bipush        10   18: if_icmplt     5   21: return         

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -