当前位置: 首页 > news >正文

湛江专业网站建设公司建设网站找哪个公司

湛江专业网站建设公司,建设网站找哪个公司,山西建筑劳务网站,怎么样做免费的百度seo最近我看到了一个关于Google Guava的精彩演讲 #xff0c;我们在我们的项目中得出结论#xff0c;使用它的缓存功能真的很有趣。 让我们看一下regexp Pattern类及其编译功能 。 在代码中经常可以看到#xff0c;每次使用正则表达式时#xff0c;程序员都会使用相同的参数重… 最近我看到了一个关于Google Guava的精彩演讲 我们在我们的项目中得出结论使用它的缓存功能真的很有趣。 让我们看一下regexp Pattern类及其编译功能 。 在代码中经常可以看到每次使用正则表达式时程序员都会使用相同的参数重复调用上述Pattern.compile函数从而一次又一次地编译相同的正则表达式。 但是可以做的是缓存此类编译的结果–让我们看一下RegexpUtils实用程序类 RegexpUtils.java package pl.grzejszczak.marcin.guava.cache.utils;import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache;import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern;import static java.lang.String.format;public final class RegexpUtils {private RegexpUtils() {throw new UnsupportedOperationException(RegexpUtils is a utility class - dont instantiate it!);}private static final LoadingCacheString, Pattern COMPILED_PATTERNS CacheBuilder.newBuilder().build(new CacheLoaderString, Pattern() {Overridepublic Pattern load(String regexp) throws Exception {return Pattern.compile(regexp);}});public static Pattern getPattern(String regexp) {try {return COMPILED_PATTERNS.get(regexp);} catch (ExecutionException e) {throw new RuntimeException(format(Error when getting a pattern [%s] from cache, regexp), e);}}public static boolean matches(String stringToCheck, String regexp) {return doGetMatcher(stringToCheck, regexp).matches();}public static Matcher getMatcher(String stringToCheck, String regexp) {return doGetMatcher(stringToCheck, regexp);}private static Matcher doGetMatcher(String stringToCheck, String regexp) {Pattern pattern getPattern(regexp);return pattern.matcher(stringToCheck);}} 如您所见如果没有找到则使用带有CacheBuilder的Guava的LoadingCache来填充具有新编译模式的缓存。 由于缓存已编译的模式如果已经进行了编译将不会再次重复在我们的情况下因为我们没有任何到期设置。 现在一个简单的测试 GuavaCache.java package pl.grzejszczak.marcin.guava.cache;import com.google.common.base.Stopwatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import pl.grzejszczak.marcin.guava.cache.utils.RegexpUtils;import java.util.regex.Pattern;import static java.lang.String.format;public class GuavaCache {private static final Logger LOGGER LoggerFactory.getLogger(GuavaCache.class);public static final String STRING_TO_MATCH something;public static void main(String[] args) {runTestForManualCompilationAndOneUsingCache(1);runTestForManualCompilationAndOneUsingCache(10);runTestForManualCompilationAndOneUsingCache(100);runTestForManualCompilationAndOneUsingCache(1000);runTestForManualCompilationAndOneUsingCache(10000);runTestForManualCompilationAndOneUsingCache(100000);runTestForManualCompilationAndOneUsingCache(1000000);}private static void runTestForManualCompilationAndOneUsingCache(int firstNoOfRepetitions) {repeatManualCompilation(firstNoOfRepetitions);repeatCompilationWithCache(firstNoOfRepetitions);}private static void repeatManualCompilation(int noOfRepetitions) {Stopwatch stopwatch new Stopwatch().start();compileAndMatchPatternManually(noOfRepetitions);LOGGER.debug(format(Time needed to compile and check regexp expression [%d] ms, no of iterations [%d], stopwatch.elapsedMillis(), noOfRepetitions));}private static void repeatCompilationWithCache(int noOfRepetitions) {Stopwatch stopwatch new Stopwatch().start();compileAndMatchPatternUsingCache(noOfRepetitions);LOGGER.debug(format(Time needed to compile and check regexp expression using Cache [%d] ms, no of iterations [%d], stopwatch.elapsedMillis(), noOfRepetitions));}private static void compileAndMatchPatternManually(int limit) {for (int i 0; i limit; i) {Pattern.compile(something).matcher(STRING_TO_MATCH).matches();Pattern.compile(something1).matcher(STRING_TO_MATCH).matches();Pattern.compile(something2).matcher(STRING_TO_MATCH).matches();Pattern.compile(something3).matcher(STRING_TO_MATCH).matches();Pattern.compile(something4).matcher(STRING_TO_MATCH).matches();Pattern.compile(something5).matcher(STRING_TO_MATCH).matches();Pattern.compile(something6).matcher(STRING_TO_MATCH).matches();Pattern.compile(something7).matcher(STRING_TO_MATCH).matches();Pattern.compile(something8).matcher(STRING_TO_MATCH).matches();Pattern.compile(something9).matcher(STRING_TO_MATCH).matches();}}private static void compileAndMatchPatternUsingCache(int limit) {for (int i 0; i limit; i) {RegexpUtils.matches(STRING_TO_MATCH, something);RegexpUtils.matches(STRING_TO_MATCH, something1);RegexpUtils.matches(STRING_TO_MATCH, something2);RegexpUtils.matches(STRING_TO_MATCH, something3);RegexpUtils.matches(STRING_TO_MATCH, something4);RegexpUtils.matches(STRING_TO_MATCH, something5);RegexpUtils.matches(STRING_TO_MATCH, something6);RegexpUtils.matches(STRING_TO_MATCH, something7);RegexpUtils.matches(STRING_TO_MATCH, something8);RegexpUtils.matches(STRING_TO_MATCH, something9);}}} 我们正在运行一系列测试并检查它们的执行时间。 请注意由于应用程序不是独立运行的因此这些测试的结果并不精确因此许多条件都可能影响执行时间。 我们有兴趣显示一定程度的问题而不是显示准确的执行时间。 对于给定的迭代次数1,10,100,1000,10000,100000,1000000我们要么编译10个正则表达式要么使用Guava的缓存检索已编译的Pattern然后将它们与要匹配的字符串进行匹配。 这些是日志 pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [1] ms, no of iterations [1] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [35] ms, no of iterations [1] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [1] ms, no of iterations [10] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [0] ms, no of iterations [10] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [8] ms, no of iterations [100] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [3] ms, no of iterations [100] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [10] ms, no of iterations [1000] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [10] ms, no of iterations [1000] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [83] ms, no of iterations [10000] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [33] ms, no of iterations [10000] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [800] ms, no of iterations [100000] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [279] ms, no of iterations [100000] pl.grzejszczak.marcin.guava.cache.GuavaCache:34 Time needed to compile and check regexp expression [7562] ms, no of iterations [1000000] pl.grzejszczak.marcin.guava.cache.GuavaCache:40 Time needed to compile and check regexp expression using Cache [3067] ms, no of iterations [1000000] 您可以在此处在Guava / Cache目录下找到源或转到URL https://bitbucket.org/gregorin1987/too-much-coding/src 参考来自Blog上的 JCG合作伙伴 Marcin Grzejszczak的正则表达式模式的Google Guava Cache 用于编码成瘾者博客。 翻译自: https://www.javacodegeeks.com/2013/04/google-guava-cache-with-regular-expression-patterns.html
http://www.pierceye.com/news/287417/

相关文章:

  • 合肥的网站建设剂屏自己可以做开奖网站吗
  • 官网设计比较好看的网站学校网站建设对教学的意义
  • 济南建站推荐企汇优见效付款毕设代做网站招聘
  • 泰然建设网站免费软件app下载大全正能量网站
  • 张掖市网站建设北京代理记账财务公司
  • 中铁建设集团网站网络公司手机网站
  • 站长工具是什么意思建设银行网站 开户行怎么查
  • 做简历模板的网站都有哪些wordpress是啥东西
  • 网站流量渠道湖州做网站优化
  • 汽车网站哪个好预付的网站开发费用怎么入账
  • 网站代管理哪个网站有介绍拿到家做的手工活
  • 惊艳的网站网站建设实训过程报告
  • 秦皇岛做网站公司企业网站备案需要什么
  • 做网站必须开厂吗科协网站建设建议
  • 西宁 网站建设凡科做视频网站
  • wordpress中文主题 wp-cmsseo排名赚钱
  • 优质的网站制作在线查企业信息查询平台
  • 天津网站建设学习电子商务企业网站建设实训报告
  • 怎么让网站收录在google怎么免费安装wordpress主题
  • 在windows2003上做网站浙江网
  • 宣威网站wordpress把logo变大
  • 网站设计模式有哪些商城网站营销方案
  • mvc做的网站wordpress 新建php文件
  • 西安网站seo外包个人开发者
  • 注册网站需要visa怎么办济宁万达网站建设
  • niche网站建设wordpress安装文本编辑器
  • 网站建设三种方法免费的导航页
  • 微信到wordpress杭州网站怎么做seo
  • 沙田镇仿做网站网站加速器quickq
  • 武进网站建设医药公司网站建设