paip.提升性能---string split



大概一万次就能看到慢的兰..

/////split 慢的原因。因为使用了正则表达式的,这样,就慢的了..



作者Attilax  艾龙,  EMAIL:1466519819@qq.com

来源:attilax的专栏

地址:http://blog.csdn.net/attilax



String.split(regex)事实上简单的调用了Pattern.compile(regex).split(this, limit),且每次compile()都会返回一个新Pattern。所以如果频繁调用split的话,最好创建单个Pattern实例并重复使用来取代split()。



 因此,如果你调用String.split非常频繁的话,每次都重新编译正则表达式的代价很高,性能会受到很大影响,此时最好自己预编译Pattern,再调用Pattern.split方法为妙。



解决:

1.预编译Pattern

 因此,如果你调用String.split非常频繁的话,每次都重新编译正则表达式的代价很高,性能会受到很大影响,此时最好自己预编译Pattern,再调用Pattern.split方法为妙。

String []items=line.split(" ");



//替代为



static Pattern pattern=Pattern.compile(" ");







String []items=pattern.split(line,0);





2.stringtoken



3.自定义分割算法

string tmp=orgSTr;

while(true)

{

  string splitstr=null;

  int j=tmp.indexof(',');

  if(j<0)break;

  splitstr=tmp.substring(0,j);

  tmp=tmp.substring(j+1);



}

 

 

 ///结果比较:

 splite 3600ms,stringtoken 2600ms, indexof 600ms..

 性能提升6倍之多阿..

 

 stringbuilder sb=new xx(99999);//预先顶好容量..

  时间是默认的1/3..提升3倍..

paip.提升性能---string split的更多相关文章

  1. paip.提升性能--多核cpu中的java/.net/php/c++编程

    paip.提升性能--多核cpu中的java/.net/php/c++编程 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http ...

  2. paip. 提升性能---hibernate的缓存使用 总结

    paip. 提升性能---hibernate的缓存使用 总结 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog ...

  3. paip.提升性能---并行多核编程哈的数据结构list,set,map

    paip.提升性能---并行多核编程哈的数据结构list,set,map vector/copyonwritearraylist 都是线程安全的. 或者经过包装的list ::: collection ...

  4. paip.提升性能----java 无锁结构(CAS, Atomic, Threadlocal, volatile, 函数式编码, 不变对象)

    paip.提升性能----java 无锁结构(CAS, Atomic, Threadlocal, volatile, 函数式编码, 不变对象) 1     锁的缺点 2     CAS(Compare ...

  5. paip.提升性能--多核编程中的java .net php c++最佳实践 v2.0 cah

    paip.提升性能--多核编程中的java .net php c++最佳实践  v2.0 cah 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax ...

  6. paip.提升性能---mysql 优化cpu多核以及lan性能的关系.

    paip.提升性能---mysql 优化cpu多核以及lan性能的关系. 作者Attilax  艾龙,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http:/ ...

  7. paip.提升性能---mysql 性能 测试以及 参数调整.txt

    paip.提升性能---mysql 性能 测试以及 参数调整.txt 作者Attilax  艾龙,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://b ...

  8. paip.提升性能---jvm java 工具使用.

    paip.提升性能---jvm java 工具使用. 作者Attilax  艾龙,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn ...

  9. paip.提升性能----jvm参数调整.txt

    paip.提升性能----jvm参数调整.txt 作者Attilax  艾龙,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.n ...

随机推荐

  1. getch 和 getchar 在 windows 和 unix下的区别

    注意getch()是从console读取,(非标准函数) getch()需要的头文件是<conio.h>. 而getchar()是从stdin,一般是指键盘 windows平台下ENTER ...

  2. PHP的OB缓存(输出缓存)

    使用PHP自带的缓存机制 原则:如果ob缓存打开,则echo的数据首先放在ob缓存.如果是header信息,直接放在程序缓存.当页面执行到最后,会把ob缓存的数据放到程序缓存,然后依次返回给浏览器. ...

  3. c# SqlHelper Class

    using System;using System.Collections;using System.Collections.Generic;using System.Data;using Syste ...

  4. Spring 4 官方文档学习(十二)View技术

    关键词:view technology.template.template engine.markup.内容较多,按需查用即可. 介绍 Thymeleaf Groovy Markup Template ...

  5. ImportError: No module named setuptools 解决方案

    shell中输入: wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz --no-che ...

  6. FreeBSD_11-系统管理——{Part_4 - 内核参数定制}

    特别提醒:自行定制的内核,必須经过全方位测试无誤后,方能用于生产环境 基于:/usr/src/sys/amd64/conf/GENERIC cpu HAMMER ident TEST_kernel # ...

  7. Points on cycle

    Description There is a cycle with its center on the origin. Now give you a point on the cycle, you a ...

  8. [Chapter 3 Process]Practice 3.4 Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.

    3.4 The Sun UltraSPARC processor has multiple register sets. Describe what happens when a context sw ...

  9. JBOSS最大连接数配置和jvm内存配置

    一.调整JBOSS最大连接数. 配置deploy/jboss-web.deployer/server.xml文件 .       <Connector         port="80 ...

  10. step by step 之餐饮管理系统三

    1.说明 表名的长度最长为18个字符 茶色的字段为主键或联合主键 浅黄色的字段为索引 浅灰底色的字段为临时表中比正式表多出的字段 数据库系统:Sqlserver2008 脚本工具:使用CodeGene ...