位运算与模运算耗时比较

package com.thunisoft.jy.yysb.rdzs;

/**
 * @author: xiepanpan
 * @Date: 2020/9/10
 * @Description:  测试位运算与取模运算
 */
public class Test1 {

    @Test
    public void bit() {
        int number = 10000 * 10;//分别取值10万100万、1000万1亿.
        int a = 1;
        long start = System.currentTimeMillis();
        for (int i = number; i > 0; i++) {
           a =a&i;
        }
        long end = System.currentTimeMillis();
        System.out.println("位运算耗时:" + (end - start));
    }

    @Test
    public void modulus() {
        int number = 10000 * 10;//分别取值10万100万、1000万1亿.
        int a = 1;
        long start = System.currentTimeMillis();
        for (int i = number; i > 0; i++) {
            a %= i;
            
        }
        long end = System.currentTimeMillis();
        System.out.println("取模运算耗时: " + (end - start));

    }
}

©️2020 CSDN 皮肤主题: 鲸 设计师:meimeiellie 返回首页