标签:style blog color os io ar strong art div
比较如下两个正则表达式:
(?:.*?(?:\\s|,)+)*no\\s+air\\s+conditioning.*?
(?:.*?(?:\\s|,)+)?no\\s+air\\s+conditioning.*?
区别仅仅在于*和?的区别,一字之差性能就相差很多:前者是35699.334;后者是108.686
完整测试代码:
String TEST_VALUE = "ABS, traction control, front and side airbags, Isofix child seat anchor points, no air conditioning, electric windows, \r\nelectrically operated door mirrors";
double start = System.nanoTime();
Pattern pattern = Pattern.compile("^(?:.*?(?:\\s|,)+)*no\\s+air\\s+conditioning.*$");
assertTrue(pattern.matcher(TEST_VALUE).matches());
double end = System.nanoTime();
LOGGER.info("Took {} micros", (end - start) / (1000 ));
两分钟以后这个程序还在运行,已经堵塞了CPU:
标签:style blog color os io ar strong art div
原文地址:http://www.cnblogs.com/muzhongjiang/p/3961222.html