简体   繁体   English

Java List.SubList()性能比较

[英]Java List.SubList() Performance comparison

I need to implement a sliding window which slides over a sequence. 我需要实现一个在序列上滑动的滑动窗口。 (1:[0,1,2,3]2:[1,2,3,4],...) Which aprove might be faster? (1:[0,1,2,3] 2:[1,2,3,4],...)哪种证明可能会更快? 1. 1。

for each step i; {List=wholeList.sublist(i,i+windowlen)}

or 2. 或2。

  List window=wholeList.sublist(0,window);
  for each i{
  window.remove(0);
  window.add(i+windowlen);

} }

?

I measured the time with system.currtime bla .. +-std the SubLists seems to work faster.. but why? 我用system.currtime bla .. + -std测量了时间,SubLists似乎工作得更快..但是为什么呢? i think the second aproach is O(n) 我认为第二个方法是O(n)

I need to operate huge databases.. therefor i need to look at this.. 我需要操作大型数据库..为此,我需要研究一下..

mfg Jan 制造商简

Assuming the remove step is only part of step 2, they aren't equivalent, so comparing them is pointless. 假设删除步骤只是步骤2的一部分,那么它们并不等效,因此比较它们是没有意义的。 The second one modifies both the subsist and the underlying list. 第二个修改了存在列表和基础列表。 I doubt whether (2) will even work. 我怀疑(2)是否会奏效。 I don't see any reason to go beyond (1). 我认为没有任何理由超越(1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM