Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JMH for java静态方法的JMH微基准测试返回OutOfBounds异常_Java_List_Benchmarking_Microbenchmark_Jmh - Fatal编程技术网

使用JMH for java静态方法的JMH微基准测试返回OutOfBounds异常

使用JMH for java静态方法的JMH微基准测试返回OutOfBounds异常,java,list,benchmarking,microbenchmark,jmh,Java,List,Benchmarking,Microbenchmark,Jmh,我设置了这个基准测试 static Random rand = new Random(); static int n = rand.nextInt(999) + 1; @Setup public static final void setup(){ int x = 1000; for (int i = 0; i < x; i++){ id.add(rand.nextInt(500) + 1); property_address.add(rand.nextInt(10

我设置了这个基准测试

static Random rand = new Random();
static int  n = rand.nextInt(999) + 1;

@Setup
public static final void setup(){
int x = 1000;
  for (int i = 0; i < x; i++){
    id.add(rand.nextInt(500) + 1);
    property_address.add(rand.nextInt(1000) + 1);
    email.add(rand.nextInt(1000) + 1);
    owner_address.add(rand.nextInt(1000) + 1);
    price.add(rand.nextInt(1000) + 1);
    date_sold.add(rand.nextInt(1000) + 1);
  }
  System.out.println("Setup Complete");

} 

   @Benchmark
   public static void getPropertybyId(){
    System.out.println(id.get(n) +", "+ property_address.get(n) +", "+ 
    first_name.get(n) +", "+ last_name.get(n) +", "+
    email.get(n) +", "+
    owner_address.get(n) +", "+
    price.get(n)+", "+
    date_sold.get(n));

} 
我得到以下错误

 java.lang.IndexOutOfBoundsException: Index: 902, Size: 0
       at java.util.ArrayList.rangeCheck(Unknown Source)
       at java.util.ArrayList.get(Unknown Source)
       at org.sample.MyBenchmark.getPropertybyId(MyBenchmark.java:80)

您在设置方法中填写了6个不同的列表,但在基准测试方法中使用了8个不同的列表。当然,这8个列表中有2个是零元素的,就像你的异常所说的(大小:0):你能告诉我为什么我的基准预热迭代会无限期运行吗?我有一个建议:不要在JMH测试中打印。您将主要测试控制台的IO性能。相反,使用
return
return id.get(n)+“、“+property\u address.get(n)+”、“+first\u name.get(n)+”、“+last\u name.get(n)+”、“+email.get(n)+”、“+owner\u address.get(n)+”、“+price.get(n)+”、“+date\u sall.get(n)我刚刚做了,而且成功了,非常感谢你花时间帮助我
 java.lang.IndexOutOfBoundsException: Index: 902, Size: 0
       at java.util.ArrayList.rangeCheck(Unknown Source)
       at java.util.ArrayList.get(Unknown Source)
       at org.sample.MyBenchmark.getPropertybyId(MyBenchmark.java:80)