Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package test;
  7.  
  8. public class Test {
  9.  
  10. void test1() {
  11. int x = 0;
  12. long b = System.currentTimeMillis();
  13. for (int i = 0; i < 100_001; i++) {
  14. int t = 0;
  15. //if (i % 10_000 == 0) {
  16. // System.out.println("loop #i = " + i);
  17. //}
  18. while (i != t++) {
  19. x++;
  20. }
  21. }
  22. long b1 = System.currentTimeMillis();
  23. System.out.println("T(test1) = " + (b1 - b));
  24. System.out.println("x(test1) = " + x);
  25. }
  26.  
  27. void test2() {
  28. int x=0;
  29. long b = System.currentTimeMillis();
  30. for (int i = 0; i < 100001; i++) {
  31. int t = 0;
  32. //if (i % 10_000 == 0) {
  33. // System.out.println("loop #i = " + i);
  34. // }
  35. while (t++ != i) {
  36. x++;
  37. }
  38. }
  39. long b1 = System.currentTimeMillis();
  40. System.out.println("T(test2) = " + (b1 - b));
  41. System.out.println("x(test2) = " + x);
  42. }
  43.  
  44.  
  45.  
  46. public static void main (String[] args) {
  47. Test t = new Test();
  48. t.test1();
  49. t.test1();
  50. t.test2();
  51. t.test2();
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement