You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by asdf2014 <gi...@git.apache.org> on 2017/06/30 01:52:30 UTC

[GitHub] zookeeper issue #290: ZOOKEEPER-2817: Using `Collections.singletonList` inst...

Github user asdf2014 commented on the issue:

    https://github.com/apache/zookeeper/pull/290
  
    Hi, @afine. Thank you for code review. It maybe due to...
    
    ```java
    // -ea -Xmx512M -Xms512M -Xmn256M -XX:+AlwaysPreTouch
    @Test
    public void testSingletonListPerformance() {
        String site = "yuzhouwan.com";
        int count = 1_0000_0000;
        long spendTime = 0;
        while (count > 0) {
            long startTime = System.nanoTime();
            Collections.singleton(site);
            long endTime = System.nanoTime();
            count--;
            spendTime += endTime - startTime;
        }
        Runtime runtime = Runtime.getRuntime();
        long totalMemory = runtime.totalMemory() / 1024 / 1024;
        long freeMemory = runtime.freeMemory() / 1024 / 1024;
        // [Collections.singleton] Spend Time: 1370786852ns = 1370.786852ms, Mem: 39/441/480 MB (diff/free/total)
        _log.info("[Collections.singleton] Spend Time: {}ns = {}ms, Mem: {}/{}/{} MB (diff/free/total)",
                spendTime, spendTime / Math.pow(10, 6), totalMemory - freeMemory, freeMemory, totalMemory);
    }
    
    // -ea -Xmx512M -Xms512M -Xmn256M -XX:+AlwaysPreTouch
    @Test
    public void testArraysAsListPerformance() {
        String site = "yuzhouwan.com";
        int count = 1_0000_0000;
        long spendTime = 0;
        while (count > 0) {
            long startTime = System.nanoTime();
            Arrays.asList(site);
            long endTime = System.nanoTime();
            count--;
            spendTime += endTime - startTime;
        }
        Runtime runtime = Runtime.getRuntime();
        long totalMemory = runtime.totalMemory() / 1024 / 1024;
        long freeMemory = runtime.freeMemory() / 1024 / 1024;
        // [Arrays.asList] Spend Time: 1549508768ns = 1549.508768ms, Mem: 195/312/507 MB (diff/free/total)
        _log.info("[Arrays.asList] Spend Time: {}ns = {}ms, Mem: {}/{}/{} MB (diff/free/total)",
                spendTime, spendTime / Math.pow(10, 6), totalMemory - freeMemory, freeMemory, totalMemory);
    }
    ```
    
    Full code is [here](https://github.com/asdf2014/yuzhouwan/blob/master/yuzhouwan-hacker/src/test/java/com/yuzhouwan/hacker/algorithms/collection/CollectionStuffTest.java#L168).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---