java - string split performance down after one code -


i test sting.split below.

import java.io.file;  public class testsplit3 {   private static final string procfs = "/proc/";    public static void main(string[] args) {     //split();     testfile(integer.parseint(args[0]) > 0);     split();   }    private static void testfile(boolean flag) {     long start = system.currenttimemillis();     if (flag) {       (int = 0; < 1000; i++) {         new file(procfs + i);       }     }     system.out.println("newfile:" + (system.currenttimemillis() - start));   }    public static void split() {     long start = system.currenttimemillis();     (int j = 0; j < 1000; j++) {       (int = 0; < 1000; i++) {         string str = "asas asa s asas asas asa sa sas as a"             + "asa sasa sa sa sas as asas as as as"             + "as sas asdasdas dasd asda sd ada d";         str.tostring().split(" ");       }     }     system.out.println("split:" + (system.currenttimemillis() - start));   } } 
 , test result: [mapred@r03c02038 longer]$ ~/opt/taobao/install/jdk-1.7.0_10/bin/java  testsplit3 0 newfile:0 split:1772 [mapred@r03c02038 longer]$ ~/opt/taobao/install/jdk-1.7.0_10/bin/java  testsplit3 1 newfile:6 split:1763 [mapred@r03c02038 longer]$ ~/jdk-1.6.0_32/bin/java testsplit3 0 newfile:0 split:2833 [mapred@r03c02038 longer]$  [mapred@r03c02038 longer]$  ~/jdk-1.6.0_32/bin/java testsplit3 1 newfile:5 split:3416 

e,in jdk7, running time consistent .but in jdk6 , 'testsplit3 0' faster 'testsplit3 1'. can tell me why??and how improve in jdk6

it due fact benchmark flawed.

a benchmark in java needs take account of fact of "jvm warmup" effects occur when start executing program:

  • code may loaded "on demand".
  • classes initialized "on demand".
  • methods jit compiled after executing executing bit.
  • by default heap starts "small" , may grows ... after each gc cycle.

these effects mean initial results benchmark loop may anomalous. code takes 1 measurement, , there's no way tell whether "warmup" effect distorting it.

reference:


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -