测试函数

测试算法性能的主函数,打个笔记,下次直接复制。需要注意:某些特定的语法,在项目启动后,存在着越跑越快的特点,需要多次尝试比较。

import java.math.BigDecimal;

/**
 * @author css
 * @date 2019/9/30 19:39
 */
public class Test {
    public static void main(String[] args) {
        String a = "abcdefghtadsa";
        {

            int cnt = 10_0000;
            long start = System.nanoTime();
            while(cnt --> 0){
                //TODO: sth.
            }
            long end = System.nanoTime();
            System.out.println(end - start);
        }
        {
            int cnt = 10_0000;
            long start = System.nanoTime();
            while(cnt --> 0){
                //TODO: sth.
            }
            long end = System.nanoTime();
            System.out.println(end - start);
        }
    }
}
原文地址:https://www.cnblogs.com/chenss15060100790/p/11681438.html