Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package test;
- public class Test {
- void test1() {
- int x = 0;
- long b = System.currentTimeMillis();
- for (int i = 0; i < 100_001; i++) {
- int t = 0;
- //if (i % 10_000 == 0) {
- // System.out.println("loop #i = " + i);
- //}
- while (i != t++) {
- x++;
- }
- }
- long b1 = System.currentTimeMillis();
- System.out.println("T(test1) = " + (b1 - b));
- System.out.println("x(test1) = " + x);
- }
- void test2() {
- int x=0;
- long b = System.currentTimeMillis();
- for (int i = 0; i < 100001; i++) {
- int t = 0;
- //if (i % 10_000 == 0) {
- // System.out.println("loop #i = " + i);
- // }
- while (t++ != i) {
- x++;
- }
- }
- long b1 = System.currentTimeMillis();
- System.out.println("T(test2) = " + (b1 - b));
- System.out.println("x(test2) = " + x);
- }
- public static void main (String[] args) {
- Test t = new Test();
- t.test1();
- t.test1();
- t.test2();
- t.test2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement