Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class StringBuilderTest {
- public static final void main(String[] args) throws Exception {
- String str = "abcdefgh"+"efghefgh";
- int imax = 1024 / str.length() * 1024 * 4;
- long time = System.currentTimeMillis();
- System.out.println("exec.tm.sec\tstr.length\tallocated memory:free memory:memory used");
- Runtime runtime = Runtime.getRuntime();
- System.out.println("0\t\t0\t\t"+runtime.totalMemory()/1024 +":"+ runtime.freeMemory()/1024+":"+(runtime.totalMemory()-runtime.freeMemory())/1024);
- StringBuilder gstrBuilder = new StringBuilder("");
- int i=0;
- int lngth;
- Pattern p = Pattern.compile("efgh");
- Matcher m;
- while (i++ < imax+1000) {
- gstrBuilder.append(str);
- m = p.matcher(gstrBuilder);
- gstrBuilder = new StringBuilder(m.replaceAll("____"));
- lngth=str.length()*i;
- if ((lngth % (1024*256)) == 0) {
- System.out.println(((System.currentTimeMillis()-time)/1000)+"sec\t\t"+lngth/1024+"kb\t\t"+runtime.totalMemory()/1024+":"+runtime.freeMemory()/1024+":"+(runtime.totalMemory()-runtime.freeMemory())/1024);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment