Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class MyClass {
  2.  
  3. public static int generateRandom(){
  4. return new Random().nextInt();
  5. }
  6.  
  7. public int generateRandomDyn(){
  8. return new Random().nextInt();
  9. }
  10. }
  11.  
  12.  
  13. public class Main {
  14.  
  15. public static void main(String[] args) {
  16.  
  17. long staticBegin = getCurrDate();
  18. for (int i = 0; i < 10000000; i++) {
  19. MyClass.generateRandom();
  20. }
  21. long staticEnd = getCurrDate();
  22. System.out.println("static time: " + (staticEnd - staticBegin) );
  23.  
  24.  
  25. long dynamicBegin = getCurrDate();
  26. for (int i = 0; i < 10000000; i++) {
  27. new MyClass().generateRandomDyn();
  28. }
  29. long dynamicEnd = getCurrDate();
  30. System.out.println("dynamic time: " + (dynamicEnd - dynamicBegin));
  31. }
  32.  
  33. public static long getCurrDate(){
  34. return System.currentTimeMillis();
  35. }
  36. }
Add Comment
Please, Sign In to add comment