You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2021/01/27 08:36:26 UTC

[GitHub] [zookeeper] lanicc commented on pull request #1578: ZOOKEEPER-4057: NIOServerCnxnFactory.selectorThreads,using List instead of HashSet

lanicc commented on pull request #1578:
URL: https://github.com/apache/zookeeper/pull/1578#issuecomment-768125661


   simple test:
   
   `public static void main(String[] args) {
           int numObj = 1;
   
           Set<Object> set = new HashSet<>();
           for (int i = 0; i < numObj; i++) {
               set.add(new Object());
           }
           System.out.println("Size of HashSet: " + GraphLayout.parseInstance(set).totalSize());
           List<Object> list = new ArrayList<>();
           for (int i = 0; i < numObj; i++) {
               list.add(new Object());
           }
           System.out.println("Size of ArrayList: " + GraphLayout.parseInstance(list).totalSize());
   
   
           long start, end;
   
           Iterator<Object> setIterator = set.iterator();
           start = System.nanoTime();
           while (setIterator.hasNext()) {
               setIterator.next();
           }
           end = System.nanoTime();
           System.out.println("HashSet iterator cost: " + (end - start));
   
           Iterator<Object> listIterator = list.iterator();
           start = System.nanoTime();
           while (listIterator.hasNext()) {
               listIterator.next();
           }
           end = System.nanoTime();
           System.out.println("ArrayList iterator cost: " + (end - start));
       }`
   
   result:
   
   _Size of HashSet: 256
   Size of ArrayList: 112
   HashSet iterator cost: 20474
   ArrayList iterator cost: 460_
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org