Category Archives: apache-commons-collection

Apache CollectionUtils Performance

I was wandering if anyone made a benchmark on Apache CollectionUtils. In my simple benchmark:

List<Integer> ints = Arrays.asList(3, 4, 6, 7,8, 0,9,2, 5, 2,1, 35,11, 44, 5,1 ,2);
    long start = System.nanoTime();
    ArrayList<Integer> filtered = new ArrayList<Integer>(ints.size());
    for (Integer anInt : ints) {
        if (anInt > 10) {
            filtered.add(anInt);
        }
    }
    long end = System.nanoTime();
    System.out.println(filtered + " (" + (end - start) + ")");

    Predicate<Integer> predicate = new Predicate<Integer>() {
        @Override
        public boolean evaluate(Integer integer) {
            return integer > 10;
        }
    };
    start = System.nanoTime();
    filtered.clear();
    CollectionUtils.select(ints, predicate,filtered);
    end = System.nanoTime();
    System.out.println(filtered + " (" + (end - start) + ")");

I got the following results:

[35, 11, 44] (127643)
[35, 11, 44] (3060230)

I must say Im a big fan of this library coz it makes the code clean and testable but currently Im working on performance sensetive project and Im afraid my affection to this library gonna harm the performances.

I know this is a really general question, but any one used this library for production env? and noticed performance issues?