java - General query about efficiency -
i'm relatively new java, having taken first class in little under year ago, , have question regarding efficiency. know that
random rng = new random(); int num = rng.nextint(101); system.out.println("random number is: " + num); //example 1 and
random rng = new random(); system.out.println("random number is: " + rng.nextint(101)); //example 2 are equivalent. question faster calculate? in mind, first example stores variable, takes ram. second example doesn't store anything, has calculate lot more things whilst printing first example.
in computing classes, taught information coming cpu's internal registers lot faster information coming ram. mean example 2 technically more efficient not having stored number variable before printing it?
i'm of course assuming not need randomly generated number @ point in program.
thank , :) kind regards
any sane compiler able perform such compile time optimizations reduce lines of code there improve readability.that not specific java(where jit takes optimizations next level)
Comments
Post a Comment