-1

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) {
      for (int i = 0; i < 1000; i++) {
        new File(PROCFS + i);
      }
    }
    System.out.println("newfile:" + (System.currentTimeMillis() - start));
  }

  public static void split() {
    long start = System.currentTimeMillis();
    for (int j = 0; j < 1000; j++) {
      for (int i = 0; i < 1000; i++) {
        String str = "asas asa s asas asas asa sa sas as as as a a"
            + "asa sasa sa sa sas as as asas as as as as as as"
            + "as as a sas asdasdas dasd asda sd ada d";
        str.toString().split(" ");
      }
    }
    System.out.println("split:" + (System.currentTimeMillis() - start));
  }
}
and 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, The running time is consistent .but in jdk6 , 'TestSplit3 0' faster than 'TestSplit3 1'. Who can tell me why??and How to improve in jdk6

fengshen
  • 11
  • 2

1 Answers1

1

It is most likely due to the fact that your benchmark is flawed.

A benchmark in Java needs to take account of the fact of the "JVM warmup" effects that occur when you start executing a program:

  • Code may be loaded "on demand".
  • Classes are initialized "on demand".
  • Methods are JIT compiled after executing executing for a bit.
  • By default the heap starts "small" and may grows ... after each GC cycle.

These effects mean that the initial results you get from a benchmark loop may be anomalous. Your code only takes one measurement, and there's no way to tell whether the "warmup" effect is distorting it.

Reference:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • thank you..i know what you mean.but the tow scene is hadoop 0.19.1 vs hadoop 0.23.6. so I want to know why.How to solve the defect? i d'not use jdk7. – fengshen Apr 20 '13 at 06:57
  • 1
    I don't see how that is relevant. If you want meaningful numbers (i.e. numbers that are worth discussing) you need to fix your benchmark. If something is meaningless, there is no point speculating on what it *might* mean. – Stephen C Apr 20 '13 at 07:00
  • en thank you. i use -XX:CICompilerCount=1 The running time is consistent in jdk6 – fengshen Apr 20 '13 at 07:08
  • I don't understand what you are saying. Consistent with what? With itself? With jdk7? With not using that JVM option? – Stephen C Apr 20 '13 at 14:02